From 385241d2c07b6e97c7bd25b4d31a9845a1c74154 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 12 Apr 2013 19:16:55 +0200 Subject: [PATCH] remove String::replace, use boost::regex_replace directly --- src/command_manager.cc | 3 ++- src/string.cc | 7 ------- src/string.hh | 2 +- src/utils.hh | 3 ++- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index 33c7cf2f..87848860 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -201,7 +201,8 @@ TokenList parse(const String& line, if (opt_token_pos_info) opt_token_pos_info->push_back({token_start, pos}); String token = line.substr(token_start, pos - token_start); - token = token.replace(R"(\\([ \t;\n]))", "\\1"); + static const Regex regex{R"(\\([ \t;\n]))"}; + token = boost::regex_replace(token, regex, "\\1"); result.push_back({type, token}); } diff --git a/src/string.cc b/src/string.cc index 06a20c43..cecf0279 100644 --- a/src/string.cc +++ b/src/string.cc @@ -50,13 +50,6 @@ std::vector split(const String& str, char separator) return res; } -String String::replace(const String& expression, - const String& replacement) const -{ - boost::regex re(expression); - return String(boost::regex_replace(*this, re, replacement)); -} - String option_to_string(const Regex& re) { return String{re.str()}; diff --git a/src/string.hh b/src/string.hh index 046544ed..edfafd02 100644 --- a/src/string.hh +++ b/src/string.hh @@ -56,7 +56,7 @@ public: auto e = utf8::advance(b, end(), (int)length); return String(b,e); } - String replace(const String& expression, const String& replacement) const; + String replace(const Regex& expression, const String& replacement) const; }; inline String operator+(const char* lhs, const String& rhs) diff --git a/src/utils.hh b/src/utils.hh index 4c1ae1f3..56bc7527 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -218,7 +218,8 @@ bool operator== (const std::unique_ptr& lhs, T* rhs) inline String escape(const String& name) { - return name.replace("([ \\t;])", R"(\\\1)"); + static Regex ex{"([ \\t;])"}; + return boost::regex_replace(name, ex, R"(\\\1)"); } template