Files Classes Functions Hierarchy
#include <iostream>#include <string>#include <stringconvert.h>
Go to the source code of this file.
Functions | |
| 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. | |
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 }
1.5.8