many: use Mu::Regex instead of std::regex

The former is PCRE-compatible, and faster than std::regex.
This commit is contained in:
Dirk-Jan C. Binnema
2022-12-30 09:58:54 +02:00
parent e97bbb83e3
commit 27ecbbdd65
8 changed files with 45 additions and 66 deletions

View File

@ -39,7 +39,6 @@
#include <cinttypes>
#include <charconv>
#include <limits>
#include <regex>
#include <glib.h>
#include <glib/gprintf.h>
@ -261,15 +260,6 @@ Mu::split(const std::string& str, char sepa)
return vec;
}
std::vector<std::string>
Mu::split(const std::string& str, const std::regex& sepa_rx)
{
std::sregex_token_iterator it(str.begin(), str.end(), sepa_rx, -1);
std::sregex_token_iterator end;
return {it, end};
}
std::string
Mu::join(const std::vector<std::string>& svec, const std::string& sepa)
{

View File

@ -33,7 +33,6 @@
#include <type_traits>
#include <algorithm>
#include <numeric>
#include <regex>
#include "mu-utils-format.hh"
#include "mu-option.hh"
@ -97,16 +96,6 @@ std::vector<std::string> split(const std::string& str, const std::string& sepa);
*/
std::vector<std::string> split(const std::string& str, char sepa);
/**
* Split a string in parts
*
* @param str a string
* @param sepa the separator regex
*
* @return the parts.
*/
std::vector<std::string> split(const std::string& str, const std::regex& sepa_rx);
/**
* Join the strings in svec into a string, separated by sepa
*
@ -173,8 +162,6 @@ bool locale_workaround();
*/
bool timezone_available(const std::string& tz);
/**
* Well-known runtime paths
*

View File

@ -220,9 +220,6 @@ test_split()
// char sepa
assert_equal_svec(split("axbxc", 'x'), {"a", "b", "c"});
assert_equal_svec(split("axbxcx", 'x'), {"a", "b", "c", ""});
// rx sexp
assert_equal_svec(split("axbyc", std::regex("[xy]")), {"a", "b", "c"});
}
static void