Skip to content
Snippets Groups Projects
Commit 0ef0b185 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Use qualified name to detect signature mismatch

parent 909f3e26
No related branches found
No related tags found
No related merge requests found
#include "string_tools.h"
#include "SimoxUtility/error/SimoxError.h"
#include <SimoxUtility/error/SimoxError.h>
#include <boost/algorithm/string.hpp>
......@@ -9,17 +9,19 @@
#include <iomanip>
#include <regex>
namespace simox::alg
namespace simox
{
std::string to_lower(const std::string& str)
std::string alg::to_lower(const std::string& str)
{
std::string res = str;
std::transform(res.begin(), res.end(), res.begin(), tolower);
return res;
}
std::string to_upper(const std::string& str)
std::string alg::to_upper(const std::string& str)
{
std::string res = str;
std::transform(res.begin(), res.end(), res.begin(), toupper);
......@@ -27,7 +29,7 @@ std::string to_upper(const std::string& str)
}
std::string capitalize_words(const std::string& str)
std::string alg::capitalize_words(const std::string& str)
{
std::regex regex("\\s[a-z]");
std::stringstream result;
......@@ -55,23 +57,33 @@ std::string capitalize_words(const std::string& str)
}
void trim(std::string& str, const std::locale& locale) {
void alg::trim(std::string& str, const std::locale& locale)
{
boost::trim(str, locale);
}
std::string trim_copy(const std::string& str, const std::locale& locale) {
std::string alg::trim_copy(const std::string& str, const std::locale& locale)
{
return boost::trim_copy(str, locale);
}
void trim_if(std::string& str, const std::string& trim) {
void alg::trim_if(std::string& str, const std::string& trim)
{
boost::trim_if(str, boost::is_any_of(trim));
}
std::string trim_copy_if(std::string& str, const std::string& trim) {
std::string alg::trim_copy_if(const std::string& str, const std::string& trim)
{
return boost::trim_copy_if(str, boost::is_any_of(trim));
}
std::vector<std::string> split(const std::string& str, const std::string& splitBy, bool trimElements, bool removeEmptyElements, const std::locale& locale)
std::vector<std::string> alg::split(
const std::string& str, const std::string& splitBy,
bool trimElements, bool removeEmptyElements, const std::locale& locale)
{
std::vector<std::string> strs;
boost::split(strs, str, boost::is_any_of(splitBy));
......@@ -93,7 +105,8 @@ std::vector<std::string> split(const std::string& str, const std::string& splitB
return strs;
}
std::vector<std::string> split_check_size(const std::string& str, unsigned int expectedSize, const std::string& splitBy, bool trimElements, bool removeEmptyElements, const std::locale& locale)
std::vector<std::string> alg::split_check_size(const std::string& str, unsigned int expectedSize, const std::string& splitBy, bool trimElements, bool removeEmptyElements, const std::locale& locale)
{
std::vector<std::string> strs = split(str, splitBy, trimElements, removeEmptyElements, locale);
......@@ -102,7 +115,8 @@ std::vector<std::string> split_check_size(const std::string& str, unsigned int e
return strs;
}
std::string join(const std::vector<std::string> vec, const std::string& delimiter, bool trimElements, bool ignoreEmptyElements, const std::locale& locale) {
std::string alg::join(const std::vector<std::string> vec, const std::string& delimiter, bool trimElements, bool ignoreEmptyElements, const std::locale& locale) {
std::ostringstream ss;
ss.imbue(locale);
for (size_t index = 0; index < vec.size(); index++)
......@@ -126,32 +140,38 @@ std::string join(const std::vector<std::string> vec, const std::string& delimite
return ss.str();
}
std::string replace_all(const std::string& input, const std::string& search, const std::string& replace)
std::string alg::replace_all(const std::string& input, const std::string& search, const std::string& replace)
{
return boost::algorithm::replace_all_copy(input, search, replace);
}
std::string replace_first(const std::string& input, const std::string& search, const std::string& replace)
std::string alg::replace_first(const std::string& input, const std::string& search, const std::string& replace)
{
return boost::algorithm::replace_first_copy(input, search, replace);
}
std::string replace_last(const std::string& input, const std::string& search, const std::string& replace)
std::string alg::replace_last(const std::string& input, const std::string& search, const std::string& replace)
{
return boost::algorithm::replace_last_copy(input, search, replace);
}
bool starts_with(const std::string& input, const std::string& search)
bool alg::starts_with(const std::string& input, const std::string& search)
{
return boost::starts_with(input, search);
}
bool ends_with(const std::string& input, const std::string& search)
bool alg::ends_with(const std::string& input, const std::string& search)
{
return boost::ends_with(input, search);
}
bool contains(const std::string& haystack, const std::string& needle)
bool alg::contains(const std::string& haystack, const std::string& needle)
{
return boost::algorithm::contains(haystack, needle);
}
......
......@@ -54,15 +54,30 @@ namespace simox::alg
std::string trim_copy_if(const std::string& str, const std::string& trim = "\t ");
std::vector<std::string> split(const std::string& str, const std::string& splitBy = "\t ", bool trimElements = true,
bool removeEmptyElements = true, const std::locale& locale = DEFAULT_LOCALE);
//! @param expectedSize throws SimoxError if split not matches expectedSize
std::vector<std::string> split_check_size(const std::string& str, unsigned int expectedSize, const std::string& splitBy = "\t ",
bool trimElements = true, bool removeEmptyElements = true, const std::locale& locale = DEFAULT_LOCALE);
std::string join(const std::vector<std::string> vec, const std::string& delimiter = " ", bool trimElements = false,
bool ignoreEmptyElements = false, const std::locale& locale = DEFAULT_LOCALE);
std::vector<std::string>
split(const std::string& str,
const std::string& splitBy = "\t ",
bool trimElements = true,
bool removeEmptyElements = true,
const std::locale& locale = DEFAULT_LOCALE);
/// @param expectedSize throws SimoxError if split not matches expectedSize
std::vector<std::string>
split_check_size(
const std::string& str,
unsigned int expectedSize,
const std::string& splitBy = "\t ",
bool trimElements = true,
bool removeEmptyElements = true,
const std::locale& locale = DEFAULT_LOCALE);
std::string
join(const std::vector<std::string> vec,
const std::string& delimiter = " ",
bool trimElements = false,
bool ignoreEmptyElements = false,
const std::locale& locale = DEFAULT_LOCALE);
std::string replace_first(std::string const& input, std::string const& search, std::string const& replace);
......@@ -73,7 +88,6 @@ namespace simox::alg
bool starts_with(std::string const& input, std::string const& search);
bool ends_with(std::string const& input, std::string const& search);
bool contains(const std::string& haystack, const std::string& needle);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment