source file of the GNU LilyPond music typesetter
- (c) 2006 Jan Nieuwenhuizen <janneke@gnu.org>
+ (c) 2006--2007 Jan Nieuwenhuizen <janneke@gnu.org>
*/
#include "std-string.hh"
return str;
}
+/*
+ TODO: this O(n^2) in #occurences of find, due to repeated copying.
+ */
string &
replace_all (string &str, string find, string replace)
{
vector<string>
string_split (string str, char c)
{
- vector<string> a;
ssize i = str.find (c);
+
+ vector<string> a;
while (i != NPOS)
{
string s = str.substr (0, i);
a.push_back (s);
- while (str[++i] == c)
- ;
+ i ++;
str = str.substr (i);
i = str.find (c);
}
a.push_back (str);
return a;
}
+
+string
+string_join (vector<string> const &strs, string infix)
+{
+ string result;
+ for (vsize i = 0; i < strs.size (); i ++)
+ {
+ if (i)
+ result += infix;
+ result += strs[i];
+ }
+
+ return result;
+}