From df8f67e3b3a35715ecd7220e93f44a85da3f3ce3 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Wed, 13 Mar 2019 21:22:45 +0100 Subject: Remove unused vespalib::Regexp::replace() method. --- vespalib/src/tests/regex/regex.cpp | 12 ------------ vespalib/src/vespa/vespalib/util/regexp.cpp | 19 ------------------- vespalib/src/vespa/vespalib/util/regexp.h | 9 --------- 3 files changed, 40 deletions(-) (limited to 'vespalib') diff --git a/vespalib/src/tests/regex/regex.cpp b/vespalib/src/tests/regex/regex.cpp index ac2c0241423..95d6a7e88e7 100644 --- a/vespalib/src/tests/regex/regex.cpp +++ b/vespalib/src/tests/regex/regex.cpp @@ -39,7 +39,6 @@ TEST("require that invalid expression fails compilation") { Regexp bad("[unbalanced"); EXPECT_FALSE(bad.valid()); EXPECT_FALSE(bad.match("nothing")); - EXPECT_EQUAL(vespalib::string("nothing"), bad.replace("nothing", "anything")); } TEST("require that * is not valid") { @@ -47,17 +46,6 @@ TEST("require that * is not valid") { EXPECT_FALSE(bad.valid()); } -TEST("require that replace works") { - Regexp rep("foo"); - EXPECT_EQUAL(vespalib::string(""), rep.replace("", "bc")); - EXPECT_EQUAL(vespalib::string("a"), rep.replace("a", "bc")); - EXPECT_EQUAL(vespalib::string("bc"), rep.replace("foo", "bc")); - EXPECT_EQUAL(vespalib::string("abc"), rep.replace("afoo", "bc")); - EXPECT_EQUAL(vespalib::string("abcd"), rep.replace("afood", "bc")); - EXPECT_EQUAL(vespalib::string("abcdbc"), rep.replace("afoodfoo", "bc")); - EXPECT_EQUAL(vespalib::string("abcdbcbc"), rep.replace("afoodfoofoo", "bc")); -} - TEST("require that prefix detection works") { EXPECT_EQUAL("", Regexp::get_prefix("")); EXPECT_EQUAL("", Regexp::get_prefix("foo")); diff --git a/vespalib/src/vespa/vespalib/util/regexp.cpp b/vespalib/src/vespa/vespalib/util/regexp.cpp index 684ed1b8fd8..71949b82ef3 100644 --- a/vespalib/src/vespa/vespalib/util/regexp.cpp +++ b/vespalib/src/vespa/vespalib/util/regexp.cpp @@ -64,25 +64,6 @@ Regexp::match(vespalib::stringref s) const return pos >= 0; } -vespalib::string Regexp::replace(vespalib::stringref s, vespalib::stringref replacement) const -{ - if ( ! valid() ) { return s; } - regex_t *preg = const_cast(static_cast(_data)); - vespalib::string modified; - int prev(0); - for(int pos(re_search(preg, s.data(), s.size(), 0, s.size(), NULL)); - pos >=0; - pos = re_search(preg, s.data()+prev, s.size()-prev, 0, s.size()-prev, NULL)) - { - modified += s.substr(prev, pos); - modified += replacement; - int count = re_match(preg, s.data()+prev, s.size()-prev, pos, NULL); - prev += pos + count; - } - modified += s.substr(prev); - return modified; -} - Regexp::~Regexp() { regex_t *preg = static_cast(_data); diff --git a/vespalib/src/vespa/vespalib/util/regexp.h b/vespalib/src/vespa/vespalib/util/regexp.h index 6a97b72cdda..fe1930d2b4a 100644 --- a/vespalib/src/vespa/vespalib/util/regexp.h +++ b/vespalib/src/vespa/vespalib/util/regexp.h @@ -56,15 +56,6 @@ public: **/ bool match(vespalib::stringref s) const; - /** - * Will replace all occurrences of this pattern is string 's' with 'replacement'. - * If called on invalid regexp it will return an unmodified copy of the input string. - * @param s text to search for mathes. - * @param replacement text to replace the pattern. - * @return modified string. - **/ - vespalib::string replace(vespalib::stringref s, vespalib::stringref replacement) const; - /** * Look at the given regular expression and identify the prefix * that must be present for a string to match it. Note that an -- cgit v1.2.3