]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/std-string.cc
Run `make grand-replace'.
[lilypond.git] / flower / std-string.cc
index 855193ecb07b0a8849e66dec01f5a3e21224b0f0..ec5ddffbd4bd05f013b666004938e7350a50ec15 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2006  Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 2006--2008  Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "std-string.hh"
@@ -57,6 +57,12 @@ to_string (unsigned u)
   return String_convert::unsigned_string (u);
 }
 
+string
+to_string (I64 b, char const *format)
+{
+  return String_convert::i64_string (b, format);
+}
+
 string
 to_string (char const *format, ...)
 {
@@ -67,21 +73,24 @@ 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)
+replace_all (string *str, string const &find, string const &replace)
 {
   ssize len = find.length ();
-  for (ssize i = str.find (find); i != NPOS; i = str.find (find, i + len))
-    str = str.replace (i, len, replace);
-  return str;
+  for (ssize i = str->find (find); i != NPOS; i = str->find (find, i + len))
+    *str = str->replace (i, len, replace);
+  return *str;
 }
 
 string &
-replace_all (string &str, char find, char replace)
+replace_all (string *str, char find, char replace)
 {
-  for (ssize i = str.find (find); i != NPOS; i = str.find (find, i + 1))
-    str[i] = replace;
-  return str;
+  for (ssize i = str->find (find); i != NPOS; i = str->find (find, i + 1))
+    (*str)[i] = replace;
+  return *str;
 }
 
 char *
@@ -89,8 +98,9 @@ string_copy (string s)
 {
   ssize len = s.length ();
   char *dest = new char[len + 1];
-  //s.copy (dest, len + 1);
-  memcpy (dest, s.c_str (), len + 1);
+  copy (s.begin (), s.end (), dest);
+  dest[len] = 0;
+  
   return dest;
 }
 
@@ -101,17 +111,18 @@ string_compare (string const &a, string const &b)
 }
 
 #include "std-vector.hh"
+
 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);
     }
@@ -119,3 +130,17 @@ string_split (string str, char 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;
+}