diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-05 10:37:41 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-05 10:37:41 +0100 |
commit | 0f2ac0c4311e4429bfa4ede1d96ce467b5dceb5b (patch) | |
tree | b4dbe07617ca818b182a18f27d0d4e6bafc91841 /stringutil.cpp | |
parent | 0c0d858e4f9423fb9697bad9a012cb67fcee75e0 (diff) |
Added tests
Diffstat (limited to 'stringutil.cpp')
-rw-r--r-- | stringutil.cpp | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/stringutil.cpp b/stringutil.cpp deleted file mode 100644 index 6eb2899..0000000 --- a/stringutil.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "stringutil.h" - -#include <boost/algorithm/string/predicate.hpp> -#include <boost/algorithm/string/case_conv.hpp> - -#include <cstdarg> - -std::string Reichwein::Stringutil::strfmt(const char* fmt, ...) -{ - va_list args; - - va_start(args, fmt); - int size = std::vsnprintf(nullptr, 0, fmt, args); - va_end(args); - - std::string result(size, ' '); - - va_start(args, fmt); - std::vsnprintf(result.data(), size + 1, fmt, args); - va_end(args); - - return result; -} - -std::vector<std::string> Reichwein::Stringutil::split(std::string value, const std::string separators) -{ - std::vector<std::string> result; - - size_t pos0 = 0; - size_t pos1 = 0; - while (pos0 < value.size()) { - pos1 = value.find_first_of(separators, pos0); - if (pos1 == std::string::npos) - pos1 = value.size(); - std::string part = value.substr(pos0, pos1 - pos0); - //std::cout << "DEBUG: " << part << std::endl << std::flush; - if (part != "") - result.push_back(part); - pos0 = value.find_first_not_of(separators, pos1); - if (pos0 == std::string::npos) - pos0 = value.size(); - } - - return result; -} - -std::string Reichwein::Stringutil::join(std::vector<std::string> vs, std::string separator) -{ - std::string s; - for (const auto& line : vs) { - if (s.size() > 0) - s += separator; - s += line; - } - - return s; -} - -bool Reichwein::Stringutil::startsWithAnyOfLower(const std::string &s, const std::vector<std::string> &list) { - for (const std::string& element : list) { - if (boost::algorithm::starts_with(boost::algorithm::to_lower_copy(s), boost::algorithm::to_lower_copy(element))) - return true; - } - return false; -} - |