本文整理汇总了C++中OTString::reset方法的典型用法代码示例。如果您正苦于以下问题:C++ OTString::reset方法的具体用法?C++ OTString::reset怎么用?C++ OTString::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OTString
的用法示例。
在下文中一共展示了OTString::reset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFromString
// This code reads up the string, discards the bookends, and saves only the gibberish itself.
// the bEscaped option allows you to load a normal ASCII-Armored file if off, and allows
// you to load an escaped ASCII-armored file (such as inside the contracts when the public keys
// are escaped with a "- " before the rest of the ------- starts.)
//
bool OTASCIIArmor::LoadFromString(OTString & theStr, // input
bool bEscaped/*=false*/,
const // This szOverride sub-string determines where the content starts, when loading.
std::string str_override/*="-----BEGIN"*/) // Default is "-----BEGIN"
{
// Should never be 0 size, as default is "-----BEGIN"
// But if you want to load a private key, try "-----BEGIN ENCRYPTED PRIVATE" instead.
// *smile*
const std::string str_end_line = "-----END"; // Someday maybe allow parameterized option for this.
// ------------------------------------------
const int nBufSize = 2100; // todo: hardcoding
const int nBufSize2 = 2048; // todo: hardcoding
// -----------------------------
char buffer1[2100]; // todo: hardcoding
std::fill(&buffer1[0], &buffer1[(nBufSize-1)], 0); // Initializing to 0.
bool bContentMode = false; // "Currently IN content mode."
bool bHaveEnteredContentMode = false; // "Have NOT YET entered content mode."
// Clear out whatever string might have been in there before.
Release();
// Load up the string from theStr,
// (bookended by "-----BEGIN ... -----" and "END-----" messages)
bool bIsEOF = false;
theStr.reset(); // So we can call theStr.sgets(). Making sure position is at start of string.
do
{
bIsEOF = !(theStr.sgets(buffer1, nBufSize2)); // 2048
std::string line = buffer1;
const char * pConstBuf = line.c_str();
char * pBuf = (char *)pConstBuf;
// It's not a blank line.
if (line.length() < 2)
{
continue;
}
// if we're on a dashed line...
else if (line.at(0) == '-' &&
line.at(2) == '-' &&
line.at(3) == '-' &&
(bEscaped ? (line.at(1) == ' ') : (line.at(1) == '-') )
)
{
// If I just hit a dash, that means there are only two options:
// a. I have not yet entered content mode, and potentially just now entering it for the first time.
if (!bHaveEnteredContentMode)
{
// str_override defaults to: "-----BEGIN" (If you want to load a private key instead,
// Try passing "-----BEGIN ENCRYPTED PRIVATE" instead of going with the default.)
//
if (line.find(str_override) != std::string::npos &&
line.at(0) == '-' &&
line.at(2) == '-' &&
line.at(3) == '-' &&
(bEscaped ? (line.at(1) == ' ') : (line.at(1) == '-'))
)
{
// OTLog::Error("Reading ascii-armored contents...");
bHaveEnteredContentMode = true;
bContentMode = true;
continue;
}
else
{
continue;
}
}
// b. I am now LEAVING content mode!
else if (bContentMode &&
// str_end_line is "-----END"
(line.find(str_end_line) != std::string::npos))
{
// OTLog::Error("Finished reading ascii-armored contents.\n");
// OTLog::vError("Finished reading ascii-armored contents:\n%s(END DATA)\n", Get());
bContentMode = false;
continue;
}
}
// Else we're on a normal line, not a dashed line.
else
{
if (bHaveEnteredContentMode && bContentMode)
{
if (line.compare(0,8,"Version:") == 0)
{
// OTLog::Error("Skipping version line...\n");
//.........这里部分代码省略.........
示例2: LoadFromString
// This code reads up the file, discards the bookends, and saves only the gibberish itself.
// the bEscaped option allows you to load a normal ASCII-Armored file if off, and allows
// you to load an escaped ASCII-armored file (such as inside the contracts when the public keys
// are escaped with a "- " before the rest of the ------- starts.)
bool OTASCIIArmor::LoadFromString(OTString & theStr, bool bEscaped/*=false*/)
{
char buffer1[2100];
memset(buffer1, 0, 2100);
bool bContentMode = false; // "currently in content mode"
bool bHaveEnteredContentMode = false; // "have yet to enter content mode"
// Clear out whatever string might have been in there before.
Release();
// Load up the string from theStr,
// (bookended by "-----BEGIN ... -----" and END messages)
bool bIsEOF = false;
theStr.reset(); // So we can call theStr.sgets(). Making sure position is at start of string.
do
{
bIsEOF = !(theStr.sgets(buffer1, 2048));
// bIsEOF = fin.getline(buffer1, 2048).eof();
std::string line = buffer1;
const char * pConstBuf = line.c_str();
char * pBuf = (char *)pConstBuf;
// It's not a blank line.
if (line.length() < 2)
{
continue;
}
// if we're on a dashed line...
else if (line.at(0) == '-' && line.at(2) == '-' && line.at(3) == '-'
&& (bEscaped ? (line.at(1) == ' ') : (line.at(1) == '-') ) )
{
// If I just hit a dash, that means there are only two options:
// a. I have not yet entered content mode, and potentially just now entering it for the first time.
if (!bHaveEnteredContentMode)
{
if (line.find("BEGIN")!=std::string::npos && line.at(0) == '-' && line.at(2) == '-' &&
line.at(3) == '-' && (bEscaped ? (line.at(1) == ' ') : (line.at(1) == '-')))
{
// OTLog::Error("Reading ascii-armored contents...");
bHaveEnteredContentMode = true;
bContentMode = true;
continue;
}
else
{
continue;
}
}
// b. I am now LEAVING content mode!
else if (bContentMode && line.find("END")!=std::string::npos)
{
// OTLog::Error("Finished reading ascii-armored contents.\n");
// OTLog::vError("Finished reading ascii-armored contents:\n%s(END DATA)\n", Get());
bContentMode = false;
continue;
}
}
// Else we're on a normal line, not a dashed line.
else
{
if (bHaveEnteredContentMode && bContentMode)
{
if (line.compare(0,8,"Version:") == 0)
{
// OTLog::Error("Skipping version line...\n");
continue;
}
}
}
// Here we save the line to member variables, if appropriate
if (bContentMode)
{
Concatenate("%s\n", pBuf);
}
}
while(!bIsEOF && (bContentMode || !bHaveEnteredContentMode));
// reset the string position back to 0
theStr.reset();
if (!bHaveEnteredContentMode)
{
OTLog::Error("Error in OTASCIIArmor::LoadFromString: EOF before ascii-armored content found.\n");
//.........这里部分代码省略.........