![]()
|
StringUtils.cppGo to the documentation of this file.00001 #include "StringUtils.hh" 00002 00003 std::strstream& StringUtils::operator >> ( std::strstream& in, bool& w ) 00004 { 00005 std::string s; 00006 00007 in >> s; 00008 00009 strip( s ); 00010 00011 if( isnum( s ) ) 00012 { 00013 int b = s2x<int>( s ); 00014 if( b > 0 ) 00015 w = true; 00016 else 00017 w = false; 00018 return in; 00019 } 00020 00021 toupper( s ); 00022 00023 if( std::strcmp( s.c_str(), "TRUE") == 0 ) 00024 w = true; 00025 else 00026 w = false; 00027 00028 return in; 00029 } 00030 00031 bool StringUtils::isnum( const std::string &s ) 00032 { 00033 for( unsigned int i=0; i<s.size(); i++ ) 00034 { 00035 // cout << "sign: \"" << s[i] << "\" " << static_cast<int>(s[i]) << endl; 00036 if( !isdigit( s[i] ) && 00037 s[i] != '.' && 00038 s[i] != 'E' && 00039 s[i] != 'e' && 00040 s[i] != '-' && 00041 s[i] != '+' && 00042 s[i] != '\0') 00043 return false; 00044 } 00045 00046 return true; 00047 } 00048 00049 void StringUtils::strip( std::string& str ) 00050 { 00051 if( str.empty() ) 00052 return; 00053 00054 std::string::size_type start = str.find_first_not_of( " \t\n\0" ); 00055 std::string::size_type end = str.find_last_not_of( " \t\n\0" ); 00056 00057 if( start == std::string::npos || end == std::string::npos ) 00058 str = ""; 00059 00060 str = str.substr( start, end - start + 1 ); 00061 }
LeoArg (C) under the terms of the
GPL
by
King Leo (Martin Oberzalek)
Documentation created by Doxygen 1.2.2 |