]> git.donarmstrong.com Git - lilypond.git/commitdiff
further tweaks to optimized scheme formatting.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 17 Jan 2007 14:03:21 +0000 (15:03 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 17 Jan 2007 14:03:21 +0000 (15:03 +0100)
lily/general-scheme.cc
scm/lily-library.scm

index a74826c8ac7984821315bc6cb023edc2358e6ed8..c52bc54ece2a7b7e9391d2357809a3fff536083c 100644 (file)
@@ -146,6 +146,20 @@ LY_DEFINE (ly_assoc_get, "ly:assoc-get",
   return default_value;
 }
 
+LY_DEFINE (ly_string_substitute, "ly:string-substitute",
+          3, 0, 0, (SCM a, SCM b, SCM s),
+          "Replace @var{a} by @var{b} in @var{s}.")
+{
+  SCM_ASSERT_TYPE (scm_is_string (a), s, SCM_ARG1, __FUNCTION__, "string");
+  SCM_ASSERT_TYPE (scm_is_string (b), s, SCM_ARG2, __FUNCTION__, "string");
+  SCM_ASSERT_TYPE (scm_is_string (s), s, SCM_ARG3, __FUNCTION__, "string");
+
+  string ss = ly_scm2string (s);
+  replace_all (ss, string (scm_i_string_chars (a)),
+                  string (scm_i_string_chars (b)));
+  return ly_string2scm (ss);
+}
+  
 LY_DEFINE (ly_number2string, "ly:number->string",
           1, 0, 0, (SCM s),
           "Convert @var{num} to a string without generating many decimals.")
@@ -165,7 +179,7 @@ LY_DEFINE (ly_number2string, "ly:number->string",
            r = 0.0;
          }
 
-      snprintf (str, sizeof (str), "%08.4f", r);
+      snprintf (str, sizeof (str), "%.4f", r);
     }
   else
     snprintf (str, sizeof (str), "%d", int (scm_to_int (s)));
index 47e1bcd3cad5f3d5497b70717e5d368bdc285092..70faac6a82b97e462f79a531f33e281f38cbd2b6 100644 (file)
@@ -426,9 +426,9 @@ found."
 ;; string
 
 (define-public (string-endswith s suffix)
-  (equal? prefix (substring s
-                           (max 0 (- (string-length s))
-                                (min (string-length s) (string-length prefix))))))
+  (equal? suffix (substring s
+                           (max 0 (- (string-length s) (string-length suffix)))
+                           (string-length s))))
             
 (define-public (string-startswith s prefix)
   (equal? prefix (substring s 0 (min (string-length s) (string-length prefix)))))