diff --git a/include/utils/string.hpp b/include/utils/string.hpp index 7cd80f05..4b584831 100644 --- a/include/utils/string.hpp +++ b/include/utils/string.hpp @@ -55,7 +55,10 @@ namespace string_util { * Replace all occurences of needle in haystack */ inline auto replace_all(const string& haystack, string needle, string replacement) { - return boost::replace_all_copy(haystack, needle, replacement); + auto result = haystack; + while (result.find(needle) != string::npos) + result = replace(result, needle, replacement); + return result; } /** diff --git a/tests/utils/test_string.cpp b/tests/utils/test_string.cpp index 5bcb98a3..26310719 100644 --- a/tests/utils/test_string.cpp +++ b/tests/utils/test_string.cpp @@ -46,7 +46,8 @@ class test_string : public unit_test { } void test_squeeze() { - CPPUNIT_ASSERT_EQUAL(string{"Squeeeze"}, string_util::squeeze("Squeeeeeze", 'e')); + CPPUNIT_ASSERT_EQUAL(string{"Squeze"}, string_util::squeeze("Squeeeeeze", 'e')); + CPPUNIT_ASSERT_EQUAL(string{"bar baz foobar"}, string_util::squeeze("bar baz foobar", ' ')); } void test_strip() {