00001 #ifndef _Q_STRING_HANDLER_HH_
00002 #define _Q_STRING_HANDLER_HH_
00003 #include <string>
00011 namespace QStringHandler {
00012 inline std::string &SwallowSpaces(std::string& s) {
00013 size_t pos=0;
00014 while(s[pos]==' ')
00015 pos++;
00016 return s.erase( 0, pos);
00017 }
00018
00019 inline std::string &RSwallowSpaces(std::string& s) {
00020 size_t pos = s.length()-1;
00021 while( s[pos] == ' ' )
00022 pos--;
00023 return s.erase( pos+1, std::string::npos );
00024 }
00025
00026
00027
00028 inline bool StringToInteger(const std::string& s, int &i) {
00029 for( unsigned int k=0; k<s.size(); k++) {
00030 if (k==0 && (s[k]=='-' || s[k]=='+')) continue;
00031 if ( isdigit(s[k]) ) continue;
00032 return false;
00033 }
00034 i = atoi(s.c_str());
00035 return true;
00036 }
00037
00038
00039 inline bool StringToBool(const std::string& s, bool &b) {
00040 if(s=="true"){b=true;return true;}
00041 if(s=="false"){b=false;return true;}
00042
00043 return false;
00044 }
00045
00046
00047
00048 inline int StringToDouble(const std::string& s, double &d) {
00049 const char *str = s.c_str();
00050 char *err;
00051 double val = ::strtod(str,&err);
00052 if ( err == str || s=="Info" || s=="info" ) {
00053 return false;
00054 }
00055 d=val;
00056 return true;
00057 }
00058
00059 }
00060 #endif