]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/std-string.cc
Merge with master
[lilypond.git] / flower / std-string.cc
index 0fdc96f5f6d78b5fbf6c890f79be1bb886cb2d70..b78b0196616aa1adde6f46b9ab64df379b523ed5 100644 (file)
@@ -3,7 +3,7 @@
 
   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"
@@ -89,8 +89,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;
 }
 
@@ -99,3 +100,25 @@ string_compare (string const &a, string const &b)
 {
   return a.compare (b);
 }
+
+#include "std-vector.hh"
+
+vector<string>
+string_split (string str, char c)
+{
+  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)
+       ;
+      str = str.substr (i);
+      i = str.find (c);
+    }
+  if (str.length ())
+    a.push_back (str);
+  return a;
+}