本文整理汇总了C++中TextParser::parse方法的典型用法代码示例。如果您正苦于以下问题:C++ TextParser::parse方法的具体用法?C++ TextParser::parse怎么用?C++ TextParser::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextParser
的用法示例。
在下文中一共展示了TextParser::parse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
/// TextParser parse.
/// parse() should be called before you start you try to do anything
/// else with the TextParser.
/// \param text Line of text that you want to parse
/// \return true on success, if false is returned, a errorMessage
/// can is stored in public member variable errorMessage.
bool TextParser::parse(std::string text)
{
// delete previous m_tokens
if (m_tokens)
{
delete []m_tokens;
m_tokens = NULL;
}
// create a queue so we can add m_tokens as we go
queue<MultiVariable> qTokens;
MultiVariable token; // used to push m_tokens on the queue
int strLength = (int)text.length();
const char* s = text.c_str();
if (text == "")
{
m_tokens = NULL;
m_numTokens = 0;
m_typeList = "";
return 1;
}
// parse the entire
bool done = false;
int index = 0; //index into the string
while(!done)
{
// if a quote is found
if (s[index] == '"')
{
// increment the index passed the quote
index++;
// remember where we started
int startIndex = index;
// search for a a corresponding end quote or the end of the string
while (!(s[index] == '"' || index == strLength))
index++;
// if the end of file was found before and ending quote then
// return an error
if (index == strLength)
{
errorMessage = "Open quote without ending quote";
return 0;
}
// now there is a string waiting between startIndex and index
// put it in a string
token.typeString = text.substr(startIndex,index - startIndex);
token.type = eDataTypeString;
// push it on the stack
qTokens.push(token);
//increment passed ending quote
index++;
}
// if a closing parenthesis was found then there is a problem
else if (s[index] == ')')
{
errorMessage = "Close parenthesis before open parenthesis";
return 0;
}
// if a parenthesis was found
else if (s[index] == '(')
{
// parse till the end parenthesis is found and then
// parse the inside of it
index++;
int startIndex = index;
// search for a breaking character or the end of the string
while (!(s[index] == ')' || index == strLength))
index++;
if (index == strLength)
{
errorMessage = "Open quote without ending quote";
return 0;
}
// now there is a string waiting between startIndex and index
//.........这里部分代码省略.........