66 #include "rnr/rnrconfig.h" 79 "0",
"false",
"f",
"off",
"low",
"disable",
"no", NULL
84 "1",
"true",
"t",
"on",
"high",
"enable",
"yes", NULL
87 size_t split(
const string &str,
const char delim,
StringVec &elems)
89 size_t n = elems.size();
95 while(std::getline(ss, item, delim) )
97 elems.push_back(item);
100 return elems.size() - n;
107 split(str, delim, elems);
112 string &
replace(
const string &what,
const string &with,
string &str)
114 size_t len = what.length();
118 if( (len == 0) || (with.find(what) != string::npos) )
124 while( (n = str.find(what)) != string::npos )
126 str.replace(n, len, with);
137 for(
size_t i = 0; i < str.size(); ++i)
139 lower.push_back(std::tolower(str[i], loc));
150 for(
size_t i = 0; i < str.size(); ++i)
152 upper.push_back(std::toupper(str[i], loc));
158 size_t gcss(
const string &str1,
const string &str2,
const size_t pos)
163 for(i = pos; (i < str1.size()) && (i < str2.size()); ++i)
165 if( str1[i] == str2[i] )
178 int tobool(
const string &str,
bool &val)
182 for(i = 0; FalseHood[i] != NULL; ++i)
184 if( str == FalseHood[i] )
191 for(i = 0; TruthHood[i] != NULL; ++i)
193 if( str == TruthHood[i] )
203 int tolong(
const string &str,
long &val)
207 return sscanf(str.c_str(),
"%li%c", &val, &sniff) == 1? OK: RC_ERROR;
210 int todouble(
const string &str,
double &val)
214 return sscanf(str.c_str(),
"%lf%c", &val, &sniff) == 1? OK: RC_ERROR;
220 bool quoteit =
false;
222 for(
size_t i = 0; i < str.length(); ++i)
228 realpurdy.append(
"\\\"");
232 realpurdy.append(
" ");
236 realpurdy.append(
"\\t");
240 realpurdy.append(
"\\n");
244 realpurdy.append(
"\\r");
248 realpurdy.append(
"\\v");
252 realpurdy.append(
"\\f");
256 realpurdy.append(
"\\");
259 if( (str[i] < 0x21) || (str[i] > 0x7e) )
261 unsigned hh = (unsigned)str[i];
264 sprintf(buf,
"\\x%02x", hh);
265 realpurdy.append(buf);
270 realpurdy.push_back(str[i]);
278 realpurdy.insert(realpurdy.begin(),
'"');
279 realpurdy.insert(realpurdy.end(),
'"');
285 string c14n(
const string &str)
301 for(
size_t i = 0; i < tokens.size(); ++i)
int tolong(const std::string &str, long &val)
Convert string to a long integer.
std::vector< std::string > StringVec
Useful types.
int tobool(const std::string &str, bool &val)
Convert string to boolean.
std::string lowercase(const std::string &str)
Convert in-place string to lower case.
const char * TruthHood[]
strings that equate to true
Of string spaces and their strangian operators.
size_t split(const std::string &str, const char delim, StringVec &elems)
Split string.
int todouble(const std::string &str, double &val)
Convert string to a double-precision floating-point number.
std::string & trim(std::string &str)
Trim string in-place of leading and trailing whitespace.
std::string prettify(const std::string &str)
Prettify string.
std::string uppercase(const std::string &str)
Convert string to upper case.
std::string & replace(const std::string &what, const std::string &with, std::string &str)
In-place replace all whats in string with with.
std::string c14n(const std::string &str)
Simple canonicalization of a string.
size_t gcss(const std::string &str1, const std::string &str2, const size_t pos=0)
Find the length of the Greatest Common SubString.
const char * FalseHood[]
Falsehood and truthhood strings. Each list termintate with a NULL.