X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Fstd-string.cc;h=1221609c6c0ce4bc2e76a140d4fcbb1ed35f3d11;hb=2b97c8acfd61925563903393337a651e53d0f2fa;hp=6d8ebd52f5ba7fe7d00319176feec7150b14eb9d;hpb=18037c60a42e96cf61b13006bb391e3699bdc45e;p=lilypond.git diff --git a/flower/std-string.cc b/flower/std-string.cc index 6d8ebd52f5..1221609c6c 100644 --- a/flower/std-string.cc +++ b/flower/std-string.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 2006 Jan Nieuwenhuizen + (c) 2006--2007 Jan Nieuwenhuizen */ #include "std-string.hh" @@ -67,6 +67,9 @@ to_string (char const *format, ...) return str; } +/* + TODO: this O(n^2) in #occurences of find, due to repeated copying. + */ string & replace_all (string &str, string find, string replace) { @@ -113,8 +116,7 @@ string_split (string str, char c) { string s = str.substr (0, i); a.push_back (s); - while (str[++i] == c) - ; + i ++; str = str.substr (i); i = str.find (c); } @@ -122,3 +124,17 @@ string_split (string str, char c) a.push_back (str); return a; } + +string +string_join (vector const &strs, string infix) +{ + string result; + for (vsize i = 0; i < strs.size (); i ++) + { + if (i) + result += infix; + result += strs[i]; + } + + return result; +}