mirror of
https://github.com/polybar/polybar.git
synced 2024-11-18 13:55:11 -05:00
fix(string_util): Proper squeezing
This commit is contained in:
parent
4d24097092
commit
d7d953d40a
2 changed files with 6 additions and 2 deletions
|
@ -55,7 +55,10 @@ namespace string_util {
|
||||||
* Replace all occurences of needle in haystack
|
* Replace all occurences of needle in haystack
|
||||||
*/
|
*/
|
||||||
inline auto replace_all(const string& haystack, string needle, string replacement) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,7 +46,8 @@ class test_string : public unit_test {
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_squeeze() {
|
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() {
|
void test_strip() {
|
||||||
|
|
Loading…
Reference in a new issue