2009-10-08 19:59:10 +02:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2009-10-08 19:59:10 +02:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2010-02-28 22:33:06 +01:00
|
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
2009-10-08 19:59:10 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "acceptbaseparser.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool AcceptBaseParser::IsWhite(int c)
|
|
|
|
{
|
|
|
|
if( c==' ' || c=='\t' )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AcceptBaseParser::SkipWhite()
|
|
|
|
{
|
|
|
|
while( IsWhite(*text) )
|
|
|
|
++text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AcceptBaseParser::RemoveWhiteFromEnd(std::string & str)
|
|
|
|
{
|
|
|
|
if( str.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
size_t i = str.size() - 1;
|
|
|
|
|
|
|
|
for( ; i!=0 && IsWhite(str[i]) ; --i);
|
|
|
|
|
|
|
|
if( !IsWhite(str[i]) )
|
|
|
|
++i;
|
|
|
|
|
|
|
|
if( i < str.size() )
|
|
|
|
str.erase(i); // erasing until the end of the string
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AcceptBaseParser::ReadParameter()
|
|
|
|
{
|
|
|
|
param.clear();
|
|
|
|
|
|
|
|
SkipWhite();
|
|
|
|
|
|
|
|
while( *text!=0 && *text!=',' && *text!=';' )
|
|
|
|
{
|
|
|
|
param += *text;
|
|
|
|
++text;
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveWhiteFromEnd(param);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AcceptBaseParser::ReadQ()
|
|
|
|
{
|
|
|
|
q = 1.0;
|
|
|
|
|
|
|
|
SkipWhite();
|
|
|
|
|
|
|
|
if( *text != ';' )
|
|
|
|
return;
|
|
|
|
|
|
|
|
++text; // skipping a semicolon
|
|
|
|
|
|
|
|
while( *text!=0 && *text!=',' && *text!='=' )
|
|
|
|
// skipping until ',' or '='
|
|
|
|
++text;
|
|
|
|
|
|
|
|
if( *text==0 || *text==',' )
|
|
|
|
return;
|
|
|
|
|
|
|
|
++text; // skipping '='
|
|
|
|
|
|
|
|
SkipWhite();
|
|
|
|
q = strtod(text, (char**)&text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AcceptBaseParser::SkipParam()
|
|
|
|
{
|
|
|
|
SkipWhite();
|
|
|
|
|
|
|
|
if( *text == ',' )
|
|
|
|
++text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AcceptBaseParser::Parse(const char * str)
|
|
|
|
{
|
|
|
|
text = str;
|
|
|
|
Init();
|
|
|
|
|
|
|
|
while( *text != 0 )
|
|
|
|
{
|
|
|
|
ReadParameter();
|
|
|
|
ReadQ();
|
|
|
|
SkipParam();
|
|
|
|
Param(param, q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|