24 #include <utils/misc/string_conversions.h> 25 #include <core/exceptions/system.h> 54 for(
unsigned int i = 0; i < str.length(); ++i) {
55 str[i] = (char)toupper(str[i]);
68 for(
unsigned int i = 0; i < str.length(); ++i) {
69 str[i] = (char)tolower(str[i]);
84 if (asprintf(&tmp,
"%u", i) == -1) {
85 throw OutOfMemoryException(
"StringConversions::tostring(const unsigned int): asprintf() failed");
102 if (asprintf(&tmp,
"%i", i) == -1) {
120 if (asprintf(&tmp,
"%li", i) == -1) {
138 if (asprintf(&tmp,
"%f", f) == -1) {
156 if (asprintf(&tmp,
"%f", d) == -1) {
173 return std::string(
"true");
175 return std::string(
"false");
187 unsigned int l = atoll(s.c_str());
199 return atoi(s.c_str());
209 return atol(s.c_str());
220 return (
float)atof(s.c_str());
231 return atof(s.c_str());
242 if ( (s ==
"true") ||
258 std::string::size_type p1 = s.find_first_not_of(
' ');
259 std::string::size_type p2 = s.find_last_not_of(
' ');
260 s = s.substr(p1 == std::string::npos ? 0 : p1,
261 p2 == std::string::npos ? s.length() - 1 : p2 - p1 + 1);
273 std::string::size_type p1 = s.find_first_not_of(
' ');
274 std::string::size_type p2 = s.find_last_not_of(
' ');
275 return s.substr(p1 == std::string::npos ? 0 : p1,
276 p2 == std::string::npos ? s.length() - 1 : p2 - p1 + 1);
286 std::map<std::string, std::string> resolve_map;
287 resolve_map[
"@BASEDIR@"] = BASEDIR;
288 resolve_map[
"@RESDIR@"] = RESDIR;
289 resolve_map[
"@CONFDIR@"] = CONFDIR;
290 resolve_map[
"@SRCDIR@"] = SRCDIR;
291 resolve_map[
"@FAWKES_BASEDIR@"] = FAWKES_BASEDIR;
293 for(std::map<std::string, std::string>::iterator it = resolve_map.begin(); it != resolve_map.end(); it++)
295 std::size_t start_pos = res.find(it->first);
296 if(start_pos != std::string::npos)
298 res.replace(start_pos, it->first.size(), it->second);
308 std::vector<std::string>
311 std::vector<std::string> res = std::vector<std::string>(s.size());
312 for(
unsigned int i = 0; i < s.size(); i++)
static std::string resolve_path(std::string s)
Resolves path-string with @...@ tags.
static std::string to_upper(std::string str)
Convert string to all-uppercase string.
Fawkes library namespace.
static std::string to_lower(std::string str)
Convert string to all-lowercase string.
static std::vector< std::string > resolve_paths(std::vector< std::string > s)
Resolves vector of path-string with @...@ tags.
static void trim_inplace(std::string &s)
Trim string.
static int to_int(std::string s)
Convert string to an int value.
static std::string trim(std::string &s)
Trim spring.
static long to_long(std::string s)
Convert string to a long int value.
static float to_float(std::string s)
Convert string to a float value.
static bool to_bool(std::string s)
Convert string to a bool value.
static double to_double(std::string s)
Convert string to a double value.
static std::string to_string(unsigned int i)
Convert unsigned int value to a string.
System ran out of memory and desired operation could not be fulfilled.
static unsigned int to_uint(std::string s)
Convert string to an unsigned int value.