16 #include <boost/algorithm/string.hpp>
23 std::string mywildcardPattern = wildcardPattern;
24 boost::replace_all(mywildcardPattern,
"\\",
"\\\\");
25 boost::replace_all(mywildcardPattern,
"^",
"\\^");
26 boost::replace_all(mywildcardPattern,
".",
"\\.");
27 boost::replace_all(mywildcardPattern,
"$",
"\\$");
28 boost::replace_all(mywildcardPattern,
"|",
"\\|");
29 boost::replace_all(mywildcardPattern,
"(",
"\\(");
30 boost::replace_all(mywildcardPattern,
")",
"\\)");
31 boost::replace_all(mywildcardPattern,
"[",
"\\[");
32 boost::replace_all(mywildcardPattern,
"]",
"\\]");
33 boost::replace_all(mywildcardPattern,
"+",
"\\+");
34 boost::replace_all(mywildcardPattern,
"/",
"\\/");
37 boost::replace_all(mywildcardPattern,
"?",
".");
38 boost::replace_all(mywildcardPattern,
"*",
".*");
41 mywildcardPattern =
"^" + mywildcardPattern +
"$";
42 std::regex pattern(mywildcardPattern);
45 return std::regex_match(text, pattern);
51 std::string result = name;
52 result.resize(
length,
' ');
57 std::vector<std::string>
StringUtils::split(
const std::string& text,
const std::string& delimiter)
59 std::vector<std::string> tokens;
65 const std::string& replacement)
67 for (
size_t i = 0; i < items.size(); ++i)
68 boost::replace_all(text, items[i], replacement);
71 std::string
StringUtils::join(
const std::vector<std::string>& joinable,
const std::string& joint)
74 size_t n = joinable.size();
77 for (
size_t i = 0; i < n - 1; ++i)
78 result += joinable[i] + joint;
79 result += joinable[n - 1];
85 std::string result = text;
86 for (std::string::size_type i = result.find(substr); i != std::string::npos;
87 i = result.find(substr))
88 result.erase(i, substr.length());
Defines a few helper functions.
std::string removeSubstring(const std::string &text, const std::string &substr)
Removes multiple occurences of given substring from a string and returns result.
std::string join(const std::vector< std::string > &joinable, const std::string &joint)
Returns string obtain by joining vector elements.
bool matchesPattern(const std::string &text, const std::string &wildcardPattern)
Returns true if text matches pattern with wildcards '*' and '?'.
std::string to_lower(std::string text)
Returns new string which is lower case of text.
void replaceItemsFromString(std::string &text, const std::vector< std::string > &items, const std::string &replacement="")
Replaces all occurences of items from string text with delimiter.
std::string padRight(const std::string &name, size_t length)
Returns string right-padded with blanks.
std::vector< std::string > split(const std::string &text, const std::string &delimeter)
Split string into vector of string using delimeter.