Esempio n. 1
0
bool
fsRecord::FromString( const vsString &string )
{
	vsString parseString = string;
	vsString token;
	
	// remove any trailing \n from the string.
	{
		size_t i = parseString.find('\n');
		if ( i != parseString.npos )
			parseString.erase(i,1);
	}
	
	Init();
	
	token = ExtractStringToken( parseString );
	
	if ( token.empty() )
		return false;
	
	m_label = token;
	
	float f = 0.f;
	int i = 0;
	
	while(!parseString.empty())
	{
		token = ExtractStringToken( parseString );
		
		// in order for it to be a float, it must contain a decimal point.
		// so if there's no decimal point, then it's not a floating point value.
		
		vsAssert(m_argCount < MAX_PARAMETERS, "Too many arguments!" );
		
		bool isAFloat = ( token.find('.') != token.npos );
		
		if ( isAFloat )
		{
			vsAssert(sscanf( token.c_str(), "%f", &f ), "Couldn't find a floating value where we expected one?");
			m_argType[m_argCount] = Arg_Float;
			m_fArg[m_argCount++] = f;
		}
		else
		{
			vsAssert(sscanf( token.c_str(), "%d", &i), "Couldn't find an integer value?" );
			m_argType[m_argCount] = Arg_Int;
			m_iArg[m_argCount++] = i;
		}
	}
	
	return true;
}
Esempio n. 2
0
bool
vsToken::ExtractFrom( vsString &string )
{
	m_type = Type_None;

	RemoveLeadingWhitespace(string);

	if ( !string.empty() )
	{
		if ( string[0] == '\"' )
		{
			m_string = ExtractStringToken(string);
			m_type = Type_String;
			return true;
		}
		else if ( string[0] == '{' )
		{
			m_type = Type_OpenBrace;
			string.erase(0,1);
			return true;
		}
		else if ( string[0] == '}' )
		{
			m_type = Type_CloseBrace;
			string.erase(0,1);
			return true;
		}
		else if ( string[0] == '\n' )
		{
			m_type = Type_NewLine;
			string.erase(0,1);
			return true;
		}
		else if ( ::IsAlpha(string[0]) )
		{
			m_string = ExtractLabelToken(string);
			m_type = Type_Label;
			return true;
		}
		else if ( ::IsNumeric( string[0]) )
		{
			vsString token = ExtractNumberToken(string);

			if ( token == "-" ) // Ugly:  handle negative nans as zeroes.
			{
				m_int = 0;
				m_type = Type_Integer;
				return false;
			}

			bool isAFloat = ( token.find('.') != token.npos );
			if ( isAFloat )
			{
				bool success = (sscanf( token.c_str(), "%f", &m_float )!=0);
				vsAssert(success, "Couldn't find a floating value where we expected one?");
				m_type = Type_Float;
				return true;
			}
			else
			{
				bool success = sscanf( token.c_str(), "%d", &m_int) != 0;
				vsAssert(success, "Couldn't find an integer value?" );
				m_type = Type_Integer;
				return true;
			}
		}
		else if ( string[0] == '#' )
		{
			// comment!
			string = vsEmptyString;
		}
		else if ( string[0] == '=' )
		{
			m_type = Type_Equals;
			string.erase(0,1);
			return true;
		}
		else
		{
			// no clue what it was!  Just treat it as a string, breaking at the next whitespace

			m_string = ExtractWhitespaceStringToken(string);
			m_type = Type_String;
			return true;
		}
	}

	return false;
}