当前位置: 首页>>代码示例>>C++>>正文


C++ TextParser::parse方法代码示例

本文整理汇总了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
//.........这里部分代码省略.........
开发者ID:carussell,项目名称:nvvg,代码行数:101,代码来源:textParser.cpp


注:本文中的TextParser::parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。