Files Classes Functions Hierarchy
#include <sstream>#include <typedefs.h>
Go to the source code of this file.
Classes | |
| class | stringconvert |
| String helper functions. More... | |
Functions | |
| template<typename T > | |
| string & | operator<< (string &str, T const &x) |
| String serialize by appending to a string with the same syntax as the operator << (ostream &,T). | |
| template<typename T > | |
| void | stringfrom (T &targ, stringc &str) |
| Convert from a string. | |
| template<typename T > | |
| void | stringto (string &str, T const data) |
| Convert to a string. | |
| template<typename T > | |
| stringc | stringto (T const data) |
| Convert to a string. | |
| boolc | isstringdigits (stringc &str) |
| Is the string digits only? | |
| boolc | isstringinteger (stringc &str) |
| Is the string an integer? Not testing the value so 7.0 is not regared as an integer. | |
| boolc | isstringzero_or_positive_real (stringc &str) |
| e.g. | |
| boolc | isstringreal (stringc &str) |
| Integers are a subset of the reals. | |
| boolc | isstringnegative (stringc &str) |
| Looks for negative sign and a real number. | |
| template<typename T > | |
| stringc | stringtag (T x, stringc &tag) |
| Helper function to wrap data in tags. | |
Is the string digits only?
Definition at line 10 of file stringconvert.cpp.
Referenced by isstringinteger(), isstringzero_or_positive_real(), and misclib_testcode::stringconverttest::unittest01().
00011 { 00012 if (str.empty()) 00013 return false; 00014 00015 for (size_t i=0; i<str.length(); ++i) 00016 { 00017 //cout << i << ":" << str[i] << " " << isdigit(str[i]) << endl; 00018 if (isdigit(str[i])==false) 00019 return false; 00020 } 00021 00022 return true; 00023 }
Is the string an integer? Not testing the value so 7.0 is not regared as an integer.
Definition at line 25 of file stringconvert.cpp.
References isstringdigits(), and isstringinteger().
Referenced by isstringinteger(), and misclib_testcode::stringconverttest::unittest01().
00026 { 00027 if (str.empty()) 00028 return false; 00029 00030 if (str[0]=='-') 00031 return isstringinteger(str.substr(1)); 00032 00033 return isstringdigits(str); 00034 }
Looks for negative sign and a real number.
Definition at line 76 of file stringconvert.cpp.
References isstringreal().
Referenced by misclib_testcode::stringconverttest::unittest01().
00077 { 00078 if (str.empty()) 00079 return false; 00080 00081 if (str[0] != '-') 00082 return false; 00083 00084 return isstringreal(str); 00085 }
Integers are a subset of the reals.
Definition at line 65 of file stringconvert.cpp.
References isstringzero_or_positive_real().
Referenced by isstringnegative(), and misclib_testcode::stringconverttest::unittest01().
00066 { 00067 if (str.empty()) 00068 return false; 00069 00070 if (str[0]=='-') 00071 return isstringzero_or_positive_real(str.substr(1)); 00072 00073 return isstringzero_or_positive_real(str); 00074 }
e.g.
float or double >= zero.
Definition at line 36 of file stringconvert.cpp.
References isstringdigits().
Referenced by isstringreal().
00037 { 00038 if (str.empty()) 00039 return false; 00040 00041 if (str[0]=='.') 00042 return isstringdigits(str.substr(1)); 00043 00044 size_t k; 00045 uint kcount=0; 00046 for (size_t i=0; i<str.length(); ++i) 00047 { 00048 if (str[i]=='.') 00049 { 00050 k=i; 00051 ++kcount; 00052 continue; 00053 } 00054 00055 if (isdigit(str[i])==false) 00056 return false; 00057 } 00058 00059 if (kcount>1) 00060 return false; 00061 00062 return true; 00063 }
| string & operator<< | ( | string & | str, | |
| T const & | x | |||
| ) | [inline] |
String serialize by appending to a string with the same syntax as the operator << (ostream &,T).
For example: string str; ... str << "t=" << t << "\n";
Definition at line 106 of file stringconvert.h.
00107 { 00108 stringstream ss; 00109 ss << x; 00110 str += ss.str(); 00111 00112 return str; 00113 }
Convert from a string.
int x; string s="35"; stringfrom(x,s);
Definition at line 116 of file stringconvert.h.
Referenced by modulereport::compile_exitstatus(), visline::handlecommand(), mazematrixD2< T >::serializeInverse(), mazegameD2state01::serializeInverse(), gobjglColor3f::serializeInverse(), gobjglVertex3f::serializeInverse(), stringtagparsertest::test02(), misclib_testcode::tokenizertest::unittest03(), and modulereport::unittests_exitstatus().
Helper function to wrap data in tags.
Definition at line 94 of file stringconvert.h.
References stringto().
Referenced by modulereport::compilerhtmldetailed(), mazematrixD2< T >::operator stringc(), mazegameD2state01::operator stringc(), cireport::report01(), modulereport::unittestshtmldetailed(), modulereport::update(), modulereport::update01(), misclib_testcode::InventoryObj::xml(), projunittests::xml(), projunittest::xml(), unittestcmd::xml(), mkerrorscompiletag::xml(), and mkerrorscompile::xml().
00095 { 00096 string s1 = "<" + tag + ">"; 00097 s1 += stringto(x); 00098 s1 += ( "</" + tag + ">\n"); 00099 return s1; 00100 }
| void stringto | ( | string & | str, | |
| T const | data | |||
| ) | [inline] |
Convert to a string.
string s; stringto(s,36);
Definition at line 123 of file stringconvert.h.
Referenced by mazematrixD2< T >::operator stringc(), mazegameD2state01::operator stringc(), windowscaleD2::operator stringc(), mazedisp03::settings(), stringtag(), and stringtagparsertest::test02().
1.5.8