]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lily-guile.cc
* python/convertrules.py (string_or_scheme): Fix spelling error
[lilypond.git] / lily / lily-guile.cc
index 1f28e78d60d8b9f91f3f8d89f7f624ed3b55dd49..f0f90afa65fbb698989fa382c52fd322d78e478d 100644 (file)
@@ -25,6 +25,7 @@
 #include "misc.hh"
 #include "offset.hh"
 #include "pitch.hh"
+#include "string-convert.hh"
 #include "source-file.hh"
 #include "version.hh"
 #include "warn.hh"
@@ -144,7 +145,7 @@ ly_scm2newstr (SCM str, size_t *lenp)
 
       if (lenp)
        *lenp = len;
-      
+
       return new_str;
     }
   return 0;
@@ -153,7 +154,7 @@ ly_scm2newstr (SCM str, size_t *lenp)
 SCM
 index_get_cell (SCM s, Direction d)
 {
-  
+
   assert (d);
   return (d == LEFT) ? scm_car (s) : scm_cdr (s);
 }
@@ -167,7 +168,7 @@ index_set_cell (SCM s, Direction d, SCM v)
     scm_set_cdr_x (s, v);
   return s;
 }
-  
+
 bool
 is_number_pair (SCM p)
 {
@@ -328,8 +329,6 @@ ly_deep_copy (SCM src)
   return src;
 }
 
-
-
 /* looks the key up in the cdrs of the alist-keys
    - ignoring the car and ignoring non-pair keys.
    Returns first match found, i.e.
@@ -352,46 +351,33 @@ ly_assoc_cdr (SCM key, SCM alist)
   if (scm_is_pair (alist))
     {
       SCM trykey = scm_caar (alist);
-      if (scm_is_pair (trykey) && to_boolean (scm_equal_p (key, scm_cdr (trykey))))
+      if (scm_is_pair (trykey)
+         && to_boolean (scm_equal_p (key, scm_cdr (trykey))))
        return scm_car (alist);
-      else
-       return ly_assoc_cdr (key, scm_cdr (alist));
+      return ly_assoc_cdr (key, scm_cdr (alist));
     }
   return SCM_BOOL_F;
 }
 
-/* LST has the form "sym1 sym2 sym3\nsym4\nsym5"
-   i.e. \n and ' ' can be used interchangeably as separators.  */
 SCM
-parse_symbol_list (char const *lst)
-{
-  char *s = strdup (lst);
-  char *orig = s;
-  SCM create_list = SCM_EOL;
-
-  char *e = s + strlen (s) - 1;
-  while (e >= s && isspace (*e))
-    *e-- = 0;
-
-  for (char *p = s; *p; p++)
-    if (*p == '\n')
-      *p = ' ';
-  
-  if (!s[0])
-    s = 0;
-  
-  while (s)
-    {
-      char *next = strchr (s, ' ');
-      if (next)
-       *next++ = 0;
-
-      create_list = scm_cons (ly_symbol2scm (s), create_list);
-      s = next;
-    }
+ly_string_array_to_scm (Array<String> a)
+{
+  SCM s = SCM_EOL;
+  for (int i = a.size () - 1; i >= 0; i--)
+    s = scm_cons (ly_symbol2scm (a[i].to_str0 ()), s);
+  return s;
+}
 
-  free (orig);
-  return create_list;
+/* SYMBOLS is a whitespace separated list.  */
+SCM
+parse_symbol_list (char const *symbols)
+{
+  while (isspace (*symbols))
+    *symbols++;
+  String s = symbols;
+  s.substitute ('\n', ' ');
+  s.substitute ('\t', ' ');
+  return ly_string_array_to_scm (String_convert::split (s, ' '));
 }
 
 SCM
@@ -699,9 +685,7 @@ ly_alist_vals (SCM alist)
 {
   SCM x = SCM_EOL;
   for (SCM p = alist; scm_is_pair (p); p = scm_cdr (p))
-    {
-      x = scm_cons (scm_cdar (p), x);
-    }
+    x = scm_cons (scm_cdar (p), x);
   return x;
 }