/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2008-2014, Tomasz Sowa * All rights reserved. * */ #include #include "acceptbaseparser.h" namespace Winix { 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); } } } // namespace Winix