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


C++ KeyValue::SetString方法代码示例

本文整理汇总了C++中KeyValue::SetString方法的典型用法代码示例。如果您正苦于以下问题:C++ KeyValue::SetString方法的具体用法?C++ KeyValue::SetString怎么用?C++ KeyValue::SetString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KeyValue的用法示例。


在下文中一共展示了KeyValue::SetString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

// The first thing it get will be the key value
KeyValue *SKS::GetKeyValue(Position &pos)
{
	// Creates the key value to be sent back
	KeyValue *val = new KeyValue();

	// Position should be located one character after the colon
	val->SetName(GetName(pos));

	// Gets rid of leading whitespace
	while(isspace(m_fileContents[pos.pos]))
		Next(pos);
	// One reaches first character determine if a string or some sort of real number
	if(m_fileContents[pos.pos] == '"')
	{
		// move position to the first value of the string
		Next(pos);

		// Creates the string that will holst the value
		char * string = new char [MAX_STATEMENT];

		// loop until the end of the string
		int stringPos = 0;
		while(m_fileContents[pos.pos] != '"')
		{
			// One thing to note is that the contents of a string
			// value don't allow comments
			// Inserts any escape characters
			if(m_fileContents[pos.pos] == '\\')
			{
				Next(pos, false);
				if(m_fileContents[pos.pos] == '"') // Quotes
					string[stringPos] = m_fileContents[pos.pos];
				else if(m_fileContents[pos.pos] == '\'') // Quote
					string[stringPos] = m_fileContents[pos.pos];
				else if(m_fileContents[pos.pos] == '\\')
					string[stringPos] = m_fileContents[pos.pos];
				else if(m_fileContents[pos.pos] == 'n') // Newline
					string[stringPos] = '\n';
				else
				{
					cerr << "Unknown escape character \'" <<
						m_fileContents[pos.pos] << "' Line: " << pos.line << endl;
					// Just put the character after the backslash
					// in anyways
					string[stringPos] = m_fileContents[pos.pos];
				}

				// Increments their position
				stringPos++;
				Next(pos, false);
			}
			else
			{
				string[stringPos] = m_fileContents[pos.pos];
				stringPos++;
				Next(pos,false);
			}
		}

		// Adds null terminator to end of string
		string[stringPos] = NULL;

		Next(pos);  // Advances to the character after the ending quotes

		// Tells the key value what it is holding
		val->SetKeyValueType(TYPE_STRING);
		val->SetString(string);
		
	}
	else if(isdigit(m_fileContents[pos.pos]) || m_fileContents[pos.pos] == '-')
	{
		int integer = 0, fraction = 0;
		// string big enough to hold an 32 bit integer
		char num[11];
		
		bool isNegitive = false;
		if(m_fileContents[pos.pos] == '-')
		{
			// Tells that the number is negitive
			isNegitive = true;

			//Advanes to the actual first number
			Next(pos);

			//Gets rid of any spaces that might be inbetween the negitive sign
			// and the start of the number
			while(isspace(m_fileContents[pos.pos]))
				Next(pos);
		}

		// Read until a space is hit or a . is hit for a real number or the semi colon
		int i = 0;
		while(isdigit(m_fileContents[pos.pos]))
		{
			num[i++] = m_fileContents[pos.pos];
			Next(pos);
			
			if(i >= 10) // Bigger number then the 2 billion of a 4 byte integer
			{
//.........这里部分代码省略.........
开发者ID:Jonathan-Hamberg,项目名称:SKS,代码行数:101,代码来源:SKS.cpp


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