24 #include <core/exceptions/system.h>
25 #include <utils/misc/string_conversions.h>
49 for (
unsigned int i = 0; i < str.length(); ++i) {
50 str[i] = (char)toupper(str[i]);
62 for (
unsigned int i = 0; i < str.length(); ++i) {
63 str[i] = (char)tolower(str[i]);
77 if (asprintf(&tmp,
"%u", i) == -1) {
79 "StringConversions::tostring(const unsigned int): asprintf() failed");
95 if (asprintf(&tmp,
"%i", i) == -1) {
112 if (asprintf(&tmp,
"%li", i) == -1) {
129 if (asprintf(&tmp,
"%f", f) == -1) {
146 if (asprintf(&tmp,
"%f", d) == -1) {
162 return std::string(
"true");
164 return std::string(
"false");
175 unsigned int l = atoll(s.c_str());
186 return atoi(s.c_str());
196 return atol(s.c_str());
206 return (
float)atof(s.c_str());
216 return atof(s.c_str());
226 if ((s ==
"true") || (s ==
"yes") || (s ==
"1")) {
240 std::string::size_type p1 = s.find_first_not_of(
' ');
241 std::string::size_type p2 = s.find_last_not_of(
' ');
242 s = s.substr(p1 == std::string::npos ? 0 : p1,
243 p2 == std::string::npos ? s.length() - 1 : p2 - p1 + 1);
254 std::string::size_type p1 = s.find_first_not_of(
' ');
255 std::string::size_type p2 = s.find_last_not_of(
' ');
256 return s.substr(p1 == std::string::npos ? 0 : p1,
257 p2 == std::string::npos ? s.length() - 1 : p2 - p1 + 1);
267 std::map<std::string, std::string> resolve_map;
268 resolve_map[
"@BASEDIR@"] = BASEDIR;
269 resolve_map[
"@RESDIR@"] = RESDIR;
270 resolve_map[
"@CONFDIR@"] = CONFDIR;
271 resolve_map[
"@SRCDIR@"] = SRCDIR;
272 resolve_map[
"@FAWKES_BASEDIR@"] = FAWKES_BASEDIR;
273 resolve_map[
"~"] = getenv(
"HOME");
275 for (std::map<std::string, std::string>::iterator it = resolve_map.begin();
276 it != resolve_map.end();
278 std::size_t start_pos = res.find(it->first);
279 if (start_pos != std::string::npos) {
280 res.replace(start_pos, it->first.size(), it->second);
290 std::vector<std::string>
293 std::vector<std::string> res = std::vector<std::string>(s.size());
294 for (
unsigned int i = 0; i < s.size(); i++) {
System ran out of memory and desired operation could not be fulfilled.
static void trim_inplace(std::string &s)
Trim string.
static std::vector< std::string > resolve_paths(std::vector< std::string > s)
Resolves vector of path-string with @...@ tags.
static std::string to_upper(std::string str)
Convert string to all-uppercase string.
static float to_float(std::string s)
Convert string to a float value.
static double to_double(std::string s)
Convert string to a double value.
static unsigned int to_uint(std::string s)
Convert string to an unsigned int value.
static bool to_bool(std::string s)
Convert string to a bool value.
static long to_long(std::string s)
Convert string to a long int value.
static std::string trim(const std::string &s)
Trim spring.
static std::string to_string(unsigned int i)
Convert unsigned int value to a string.
static int to_int(std::string s)
Convert string to an int value.
static std::string resolve_path(std::string s)
Resolves path-string with @...@ tags.
static std::string to_lower(std::string str)
Convert string to all-lowercase string.
Fawkes library namespace.