summaryrefslogtreecommitdiff
path: root/src/utils/stringutils.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-02-05 17:19:22 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-02-05 17:22:25 +0100
commit2f2274e959f3452e847800d7496458360f21c341 (patch)
treee263a33f85bb95bbb56f1f661adf14228305bafb /src/utils/stringutils.cpp
parent3405b046701e9c08972c1e622259164fc88ac487 (diff)
downloadmana-2f2274e959f3452e847800d7496458360f21c341.tar.gz
mana-2f2274e959f3452e847800d7496458360f21c341.tar.bz2
mana-2f2274e959f3452e847800d7496458360f21c341.tar.xz
mana-2f2274e959f3452e847800d7496458360f21c341.zip
Updated C++ standard to C++17
C++17 should be universal enough by now. This raises the minimum CMake to 3.8, which should also pose no problem since Ubuntu 18.04 already shipped with CMake 3.10. C++17's 'if' initialization statement is now used in an efficient implementation of 'join' for vector<string>, found on StackOverflow.
Diffstat (limited to 'src/utils/stringutils.cpp')
-rw-r--r--src/utils/stringutils.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 5083770c..57138005 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -85,7 +85,7 @@ const char *ipToString(int address)
std::string strprintf(char const *format, ...)
{
char buf[256];
- va_list(args);
+ va_list args;
va_start(args, format);
int nb = vsnprintf(buf, 256, format, args);
va_end(args);
@@ -191,7 +191,7 @@ bool getBoolFromString(const std::string &text, bool def)
return def;
}
-std::string autocomplete(std::vector<std::string> &candidates,
+std::string autocomplete(const std::vector<std::string> &candidates,
std::string base)
{
auto i = candidates.begin();
@@ -232,7 +232,7 @@ std::string normalize(const std::string &name)
return toLower(trim(normalized));
}
-std::string removeTrailingSymbol(const std::string& s, const char c)
+std::string removeTrailingSymbol(const std::string &s, const char c)
{
// Remove the trailing symblol at the end of the string
if (!s.empty() && s.at(s.size() - 1) == c)
@@ -240,7 +240,7 @@ std::string removeTrailingSymbol(const std::string& s, const char c)
return std::string(s);
}
-std::string getHostNameFromURL(const std::string& url)
+std::string getHostNameFromURL(const std::string &url)
{
std::string myHostName;
@@ -276,3 +276,15 @@ std::string getHostNameFromURL(const std::string& url)
return myHostName;
}
+
+std::string join(const std::vector<std::string> &strings, const char *separator)
+{
+ std::string result;
+ if (auto i = strings.begin(), e = strings.end(); i != e)
+ {
+ result += *i++;
+ for (; i != e; ++i)
+ result.append(separator).append(*i);
+ }
+ return result;
+}