#include <Util.h>
Static Public Member Functions | |
int | atoi (const std::string &InStr) |
converts an std::string to an integer | |
int | atoi (const std::string &InStr) |
converts an std::string to an integer | |
int | atoi (const std::string &InStr) |
converts an std::string to an integer | |
int | atoi (const std::string &InStr) |
converts an std::string to an integer | |
std::string | basename (const std::string &path) |
std::string | basename (const std::string &path) |
std::string | basename (const std::string &path) |
std::string | basename (const std::string &path) |
int | catchOptionVal (std::string *toCatch, const int ops=0, const std::string &openDel=std::string("#("), const std::string &closeDel=std::string(")")) |
int | catchOptionVal (std::string *toCatch, const int ops=0, const std::string &openDel=std::string("#("), const std::string &closeDel=std::string(")")) |
int | expandEnvVar (std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")")) |
int | expandEnvVar (std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")")) |
int | expandEnvVar (std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")")) |
int | expandEnvVar (std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")")) |
const char * | itoa (int val, std::string &outStr) |
const char * | itoa (int val, std::string &outStr) |
const char * | itoa (int val, std::string &outStr) |
const char * | itoa (int val, std::string &outStr) |
void | keyValueTokenize (std::string input, const std::string &delimiters, std::map< std::string, std::string > &tokenMap, const std::string &pairDelimiter=std::string("="), bool clear=true) |
void | keyValueTokenize (std::string input, const std::string &delimiters, std::map< std::string, std::string > &tokenMap, const std::string &pairDelimiter=std::string("="), bool clear=true) |
double | stringToDouble (const std::string &InStr) |
double | stringToDouble (const std::string &InStr) |
double | stringToDouble (const std::string &InStr) |
double | stringToDouble (const std::string &InStr) |
int | stringToInt (const std::string &InStr) |
int | stringToInt (const std::string &InStr) |
int | stringToInt (const std::string &InStr) |
int | stringToInt (const std::string &InStr) |
void | stringTokenize (std::string input, const std::string &delimiters, std::vector< std::string > &tokens, bool clear=true) |
void | stringTokenize (std::string input, const std::string &delimiters, std::vector< std::string > &tokens, bool clear=true) |
void | stringTokenize (std::string input, const std::string &delimiters, std::vector< std::string > &tokens, bool clear=true) |
void | stringTokenize (std::string input, const std::string &delimiters, std::vector< std::string > &tokens, bool clear=true) |
unsigned | trimTrailing (std::string *toTrim) |
unsigned | trimTrailing (std::string *toTrim) |
|
converts an std::string to an integer
|
|
converts an std::string to an integer
|
|
converts an std::string to an integer
|
|
converts an std::string to an integer
00081 { 00082 // Purpose and Method: Provide a standard routine to convert std::strings 00083 // into integers. The method used depends upon the availability of 00084 // the stringstream classes. The stringstream classes are the 00085 // standard, but some compilers do yet support them. 00086 // The method used is determined by the DEFECT_NO_STRINGSTREAM 00087 // macro, defined in the facilities requirements file. 00088 // Output: returns an integer 00089 // if string cannot be converted to an integer, returns zero 00090 00091 int val; 00092 00093 #ifdef DEFECT_NO_STRINGSTREAM 00094 std::istrstream locStream(inStr.c_str()); 00095 #else 00096 std::istringstream locStream(inStr); 00097 #endif 00098 locStream >> val; 00099 if (!locStream) {return 0;} 00100 return val; 00101 }
|
|
return the "non-directory" part of a (supposed) file identifier, path. Environment variable translation should be done before calling basename.
|
|
return the "non-directory" part of a (supposed) file identifier, path. Environment variable translation should be done before calling basename.
|
|
return the "non-directory" part of a (supposed) file identifier, path. Environment variable translation should be done before calling basename.
|
|
return the "non-directory" part of a (supposed) file identifier, path. Environment variable translation should be done before calling basename.
00160 { 00161 std::vector<std::string> names; 00162 stringTokenize(path, "\\/", names); 00163 return *(names.end() - 1); 00164 }
|
|
Given input string toCatch catch val from string opt, by default of the form #(opt) and remove "#(opt)" from the original string.
|
|
Given input string toCatch catch val from string opt, by default of the form #(opt) and remove "#(opt)" from the original string.
|
|
Given input string toExpand expand references to environment variables, by default of the form and put the expanded version back into the original string. Alternate delimiters for the varname may optionally be specified
|
|
Given input string toExpand expand references to environment variables, by default of the form and put the expanded version back into the original string. Alternate delimiters for the varname may optionally be specified
|
|
Given input string toExpand expand references to environment variables, by default of the form and put the expanded version back into the original string. Alternate delimiters for the varname may optionally be specified
|
|
Given input string toExpand expand references to environment variables, by default of the form and put the expanded version back into the original string. Alternate delimiters for the varname may optionally be specified
|
|
Given an input integer val to convert and an output string outStr converts val into a std::string. This method duplicates the stdlib.h method itoa, except that it returns std::string rather than char*.
|
|
Given an input integer val to convert and an output string outStr converts val into a std::string. This method duplicates the stdlib.h method itoa, except that it returns std::string rather than char*.
|
|
Given an input integer val to convert and an output string outStr converts val into a std::string. This method duplicates the stdlib.h method itoa, except that it returns std::string rather than char*.
|
|
Given an input integer val to convert and an output string outStr converts val into a std::string. This method duplicates the stdlib.h method itoa, except that it returns std::string rather than char*.
00054 { 00055 // Purpose and Method: Provide a standard routine to convert integers 00056 // into std::string. The method used depends upon the availability of 00057 // the stringstream classes. The stringstream classes are the 00058 // standard, but some compilers do yet support them. 00059 // The method used is determined by the DEFECT_NO_STRINGSTREAM 00060 // macro, defined in the facilities requirements file. 00061 00062 static char outCharPtr[20]; 00063 00064 #ifdef DEFECT_NO_STRINGSTREAM 00065 // Using static buffer to avoid problems with memory allocation 00066 char a[100]=""; 00067 std::ostrstream locStream(a,100); 00068 #else 00069 std::ostringstream locStream; 00070 locStream.str(""); 00071 #endif 00072 locStream << val; 00073 #ifdef DEFECT_NO_STRINGSTREAM 00074 locStream << std::ends; 00075 #endif 00076 outStr = locStream.str(); 00077 strcpy(outCharPtr, outStr.c_str()); 00078 return outCharPtr; 00079 }
|
|
This routine breaks down a string into key/value token pairs and stores them in the user-supplied map. , based on the characters appearing in the string delimiters and the value of pairDelimiter. In a typical example, input could be "key1=val1,key2=val2,key3=val3". In this case invoke with delimiters=std::string(",") and pairDelimiter=std::string("=") (or omit pairDelimiter since it has the default value)
|
|
This routine breaks down a string into key/value token pairs and stores them in the user-supplied map. , based on the characters appearing in the string delimiters and the value of pairDelimiter. In a typical example, input could be "key1=val1,key2=val2,key3=val3". In this case invoke with delimiters=std::string(",") and pairDelimiter=std::string("=") (or omit pairDelimiter since it has the default value)
00142 { 00143 if (clear) tokens.clear(); 00144 00145 std::vector<std::string> strvec; 00146 stringTokenize(input,delimiters,strvec,true); 00147 unsigned advance = pairDelimiter.size(); 00148 00149 std::vector<std::string>::const_iterator input_itr = strvec.begin(); 00150 while(input_itr!=strvec.end()) 00151 { 00152 std::string current = *input_itr++; 00153 std::string::size_type j = current.find(pairDelimiter); 00154 std::string key = current.substr(0, j); 00155 std::string value = current.substr(j+advance); 00156 tokens[key] = value; 00157 } 00158 }
|
|
converts a std::string to a double. If string contents are not of proper form, throws facilities::WrongType |
|
converts a std::string to a double. If string contents are not of proper form, throws facilities::WrongType |
|
converts a std::string to a double. If string contents are not of proper form, throws facilities::WrongType |
|
converts a std::string to a double. If string contents are not of proper form, throws facilities::WrongType 00103 { 00104 double val; 00105 char junk[3]; 00106 int nItem = sscanf(inStr.c_str(), "%lg %1s", &val, junk); 00107 if (nItem != 1) { 00108 throw WrongType(inStr, "double"); 00109 } 00110 return val; 00111 }
|
|
converts a std::string to an int. If string contents are not of proper form, throws facilities::WrongType |
|
converts a std::string to an int. If string contents are not of proper form, throws facilities::WrongType |
|
converts a std::string to an int. If string contents are not of proper form, throws facilities::WrongType |
|
converts a std::string to an int. If string contents are not of proper form, throws facilities::WrongType 00114 { 00115 int val; 00116 char junk[3]; 00117 int nItem = sscanf(inStr.c_str(), "%d %1s", &val, junk); 00118 if (nItem != 1) { 00119 throw WrongType(inStr, "int"); 00120 } 00121 return val; 00122 }
|
|
This routine breaksdown a string into tokens, based on the characters appearing in the string delimiters.
|
|
This routine breaks down a string into tokens, based on the characters appearing in the string delimiters.
|
|
This routine breaksdown a string into tokens, based on the characters appearing in the string delimiters.
|
|
This routine breaks down a string into tokens, based on the characters appearing in the string delimiters.
00125 { 00126 if (clear) tokens.clear(); 00127 00128 std::string::size_type j; 00129 while ( (j = input.find_first_of(delimiters)) != std::string::npos ) { 00130 if (j != 0) tokens.push_back(input.substr(0, j)); 00131 input = input.substr(j+1); 00132 } 00133 tokens.push_back(input); 00134 if (tokens.back() == "") tokens.pop_back(); 00135 }
|
|
Trim trailing white space characters from the supplied string. White space characters for this purpose are blank, carriage return, line feed and form feed. Return # of characters trimmed. |
|
Trim trailing white space characters from the supplied string. White space characters for this purpose are blank, carriage return, line feed and form feed. Return # of characters trimmed. 00166 { 00167 static const char blank=' '; 00168 static const char LF=0xA; // new line 00169 static const char FF=0xC; // form feed 00170 static const char CR=0xD; // carriage return 00171 00172 unsigned orig = toTrim->size(); 00173 unsigned last = orig - 1; 00174 bool notDone = true; 00175 unsigned nTrimmed = 0; 00176 00177 00178 while (notDone) { 00179 char lastChar = (*toTrim)[last]; 00180 switch (lastChar) { 00181 case blank: 00182 case LF: 00183 case FF: 00184 case CR: 00185 last--; 00186 nTrimmed++; 00187 break; 00188 default: 00189 notDone=false; 00190 break; 00191 } 00192 } 00193 if (nTrimmed) toTrim->resize(orig - nTrimmed); 00194 00195 return nTrimmed; 00196 }
|