29std::string &
trim(std::string &str)
31 std::string::size_type pos = str.find_last_not_of(
' ');
32 if (pos != std::string::npos)
35 pos = str.find_first_not_of(
' ');
37 if (pos != std::string::npos)
50 std::transform(str.begin(), str.end(), str.begin(), tolower);
56 std::transform(str.begin(), str.end(), str.begin(), toupper);
60unsigned int atox(
const std::string &str)
63 sscanf(str.c_str(),
"0x%06x", &value);
70 static char asciiIP[16];
72 snprintf(asciiIP, 16,
"%i.%i.%i.%i",
73 (
unsigned char)(address),
74 (
unsigned char)(address >> 8),
75 (
unsigned char)(address >> 16),
76 (
unsigned char)(address >> 24));
85 va_start(args, format);
86 int nb = vsnprintf(buf, 256, format, args);
95 std::string res(nb,
char());
96 va_start(args, format);
97 vsnprintf(res.data(), nb, format, args);
103 std::string_view chars,
108 if (chars.find(c) != std::string::npos)
116 auto pos = msg.find(
"##");
117 while (pos != std::string::npos && msg.length() - pos >= 3)
120 pos = msg.find(
"##", pos);
127 return (chr ==
' ' || chr ==
',' || chr ==
'.' || chr ==
'"');
131 const std::string &str2)
133 int minLength = str1.length() > str2.length() ? str2.length() : str1.length();
134 for (
int f = 0; f < minLength; f ++)
136 if (str1.at(f) != str2.at(f))
138 return str1.substr(0, f);
141 return str1.substr(0, minLength);
147 if (text ==
"true" || text ==
"1" || text ==
"on" || text ==
"yes" || text ==
"y")
149 if (text ==
"false" || text ==
"0" || text ==
"off" || text ==
"no" || text ==
"n")
163 while (*p ==
' ' || *p ==
',')
168 int v =
static_cast<int>(strtol(p, &end, 10));
184 auto i = candidates.begin();
188 while (i != candidates.end())
192 std::string name = *i;
195 std::string::size_type pos = name.find(base, 0);
198 if (!newName.empty())
218 std::string normalized = name;
224 std::string directory = url;
227 size_t pos = directory.find(
"://");
228 if (pos != std::string::npos)
229 directory.erase(0, pos + 3);
235 pos = directory.find(
"..");
236 while (pos != std::string::npos)
238 directory.replace(pos, 2,
"_");
239 pos = directory.find(
"..");
245std::string
join(
const std::vector<std::string> &strings,
const char *separator)
248 if (
auto i = strings.begin(), e = strings.end(); i != e)
252 result.append(separator).append(*i);
void fromString(const char *str, std::vector< int > &value)
std::string & replaceCharacters(std::string &str, std::string_view chars, char replacement)
Replaces a set of characters with another character.
unsigned int atox(const std::string &str)
Converts an ascii hexidecimal string to an integer.
bool isWordSeparator(char chr)
Tells wether the character is a word separator.
std::string & toUpper(std::string &str)
Converts the given string to upper case.
std::string getDirectoryFromURL(const std::string &url)
Derives a directory from the given URL, stripping the schema and replacing certain invalid characters...
bool getBoolFromString(std::string text, bool def)
Returns a bool value depending on the given string value.
std::string & toLower(std::string &str)
Converts the given string to lower case.
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.
std::string join(const std::vector< std::string > &strings, const char *separator)
Joins a vector of strings into one string, separated by the given separator.
std::string & trim(std::string &str)
Trims spaces off the end and the beginning of the given string.
std::string findSameSubstring(const std::string &str1, const std::string &str2)
const char * ipToString(int address)
Converts the given IP address to a string.
std::string normalize(const std::string &name)
Normalize a string, which means lowercase and trim it.
std::string autocomplete(const std::vector< std::string > &candidates, std::string base)
Returns the most approaching string of base from candidates.
std::string & removeColors(std::string &msg)
Removes colors from a string.