Functional string helpers.
This module is designed to work with the datcxx build tool. To add this
module to your project us the following command...
build add datcxx/util-stringbuild testSearch a string for regular expression matches, returns a vector<string>.
std::string f = "/test/parallel/test-path.js";
std::vector<string> r = search(f, "\\w+");
// r.size() == 5Same as search but return a cmatch starting with the complete input at
index 0. This will potentially be depricated.
std::string f = "/test/parallel/test-path.js";
cmatch r = match(f, "/(\\w+)/(.*)");
// r.size() == 3Split on a regular expression.
std::string f = "/test/parallel/test-path.js";
vector<string> r = split(f, "/");
// r.size() == 4Test if a string is an exact match.
std::string f = "/test/parallel/test-path.js";
bool r = test(f, "^/(\\w+)/(\\w+)/(\\w+)-path.js$");
// r == truestring r = trim("/foobar//", "/");
// r.trim() == "foobar"
string r = rtrim("!Hello, World!!", "!");
// r == "!Hello, World"
string r = ltrim("!Hello, World!!", "!");
// r == "Hello, World!!"string r = replace("Hello, World!", "o", "x");
// r == "Hellx, Wxrld!"const string s = "Hello, World!";
string r = replace(s, "l", [&](string const& m, int index) {
return string("L" + to_string(index));
});
// r == "HeL0L1o, WorL2d!"