sqldata/parameters.cpp
// Load parameters from a string only
Load parameters from a string only
Load parameters from a string only
int Parameters::LoadStrItem(const char *input)
{
	if(input == NULL)
		return -1;
	const char *cur = input;
	while(*cur)
	{
		std::string name;
		std::string value;
		cur = Str::SkipSpaces(cur);
		if(*cur == '?' || (*cur == '-' && cur[1] == '?'))
		{
			_map.insert(ParametersPair(HELP_PARAMETER, "yes"));
			break;
		}
		while(*cur && *cur != '=' && *cur != '\r' && *cur != '\n' && *cur != '\t')
		{
			if(*cur == PARAMETER_START_TOKEN && name.empty() == false)
				break;
			name += *cur;
			cur++;
		}
		Str::TrimTrailingSpaces(name);
		if(*cur == '=')
			cur++;
		cur = Str::SkipSpaces(cur);
		while(*cur && *cur != '\r' && *cur != '\n' && *cur != '\t')
		{
			if(*cur == PARAMETER_START_TOKEN && cur[-1] == ' ' && cur[1] != ' ')
				break;
			value += *cur;
			cur++;
		}
		Str::TrimTrailingSpaces(value);
		std::transform(name.begin(), name.end(), name.begin(), ::tolower);
		if(_map.count(name) == 0)
		{
			_map.insert(ParametersPair(name, value));
		}
	}
	return 0;
}
int Parameters :: LoadStrItem ( const char * input ) { if ( input == NULL ) return -1 ; const char * cur = input ; while ( * cur ) { std :: string name ; std :: string value ; cur = Str :: SkipSpaces ( cur ) ; if ( * cur == ' ' || ( * cur == ' ' && cur [ 1 ] == ' ' ) ) { _map . insert ( ParametersPair ( HELP_PARAMETER , " " ) ) ; break ; } while ( * cur && * cur != ' ' && * cur != ' \r ' && * cur != ' \n ' && * cur != ' \t ' ) { if ( * cur == PARAMETER_START_TOKEN && name . empty ( ) == false ) break ; name += * cur ; cur ++ ; } Str :: TrimTrailingSpaces ( name ) ; if ( * cur == ' ' ) cur ++ ; cur = Str :: SkipSpaces ( cur ) ; while ( * cur && * cur != ' \r ' && * cur != ' \n ' && * cur != ' \t ' ) { if ( * cur == PARAMETER_START_TOKEN && cur [ -1 ] == ' ' && cur [ 1 ] != ' ' ) break ; value += * cur ; cur ++ ; } Str :: TrimTrailingSpaces ( value ) ; std :: transform ( name . begin ( ) , name . end ( ) , name . begin ( ) , :: tolower ) ; if ( _map . count ( name ) == 0 ) { _map . insert ( ParametersPair ( name , value ) ) ; } } return 0 ; }
Load parameters from a string only
Load parameters from a string only
// Process parameters // Check for help option specified as ? or /? // Add help option and ignore all remaining options // Get the parameter name until = or new line // Check for parameter without value // Get the parameter value until - or new line // if - is faced, previuos must be space, next mustn't be space (to allow - in directory path, host names etc.) // Parameter names are case-insensitive, convert to lower case // Don't add parameter if it already exists (give priority to command line and parameters defined first)