]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/string.cc
* flower/include/axis.hh: rename from axes.hh
[lilypond.git] / flower / string.cc
index 5279b6a2d5e7ff6f9f83390aee7b463e926cd33a..32ac7fca6088bc6fce8b53da4455c7f7a12a20e9 100644 (file)
@@ -168,7 +168,7 @@ String::compare (String const &s1, String const &s2)
   /*
     don't forget the terminating '\0'
   */
-  int f = (s1.length () <? s2.length ());
+  int f = min (s1.length (), s2.length ());
   int cmp_length = 1+ f;
   int i = memcmp (p1, p2, cmp_length);
   return i;
@@ -348,7 +348,7 @@ String::to_lower ()
 void
 String::reverse ()
 {
-  strrev (get_bytes (), length ());
+  memrev (get_bytes (), length ());
 }
 
 int
@@ -382,9 +382,26 @@ String::print_on (ostream &os) const
 }
 #endif
 
-void
-String::substitute_char (char chr, String sub)
+String
+String::substitute (String find, String replace)
+{
+  int n = find.length ();
+  int m = replace.length ();
+  for (int i = index (find), j = 0; i > -1;
+       i = right_string (length () - j).index (find))
+    {
+      *this = left_string (i + j)
+       + replace
+       + right_string (length () - j - i - n);
+      j += i + m;
+    }
+  return *this;
+}
+
+String
+String::substitute (char find, char replace)
 {
-  for (int i = index (chr); i > -1; i = index (chr))
-    *this = left_string (i) + sub + right_string (length () - i - 1);
+  for (int i = index (find); i > - 1; i = index (find))
+    (*this)[i] = replace;
+  return *this;
 }