1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-25 13:55:47 -05:00

fix(string_util): Proper squeezing

This commit is contained in:
Michael Carlberg 2016-10-18 06:22:44 +02:00
parent 4d24097092
commit d7d953d40a
2 changed files with 6 additions and 2 deletions

View file

@ -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;
}
/**

View file

@ -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() {