1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[css2xpath] preg_replace

This commit is contained in:
Witold Filipczyk 2021-09-30 19:15:44 +02:00
parent b67d79a661
commit e3849e567f

View File

@ -3,6 +3,7 @@
#include <sstream> #include <sstream>
#include <iterator> #include <iterator>
#include <utility> #include <utility>
#include <regex>
std::string std::string
implode(const char *const delim, std::vector<std::string> x) implode(const char *const delim, std::vector<std::string> x)
@ -36,6 +37,12 @@ explode(char delim, std::string const & s)
return result; return result;
} }
std::string
preg_replace(std::string pattern, const char *replacement, std::string subject)
{
return std::regex_replace(subject, std::regex(pattern), replacement);
}
#if 0 #if 0
#include <iostream> #include <iostream>
int int
@ -50,12 +57,20 @@ main(int argc, char **argv)
std::string res = implode(argv[1], x); std::string res = implode(argv[1], x);
std::cout << res << "\n"; std::cout << res << "\n";
#endif #endif
#if 0
auto v = explode(' ', "hello world foo bar"); auto v = explode(' ', "hello world foo bar");
for (auto e : v) for (auto e : v)
{ {
std::cout << e << "\n"; std::cout << e << "\n";
} }
#endif
std::string str = "April 15, 2003";
std::string pattern = "(\\w+) (\\d+), (\\d+)";
const char *replacement = "$1,1,$3";
std::cout << preg_replace(pattern, replacement, str);
return 0; return 0;
} }