lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Clear fret-diagram- and harp-pedal-input-strings from whitespace (issue


From: thomasmorley65
Subject: Clear fret-diagram- and harp-pedal-input-strings from whitespace (issue 257580043 by address@hidden)
Date: Sun, 23 Aug 2015 14:09:58 +0000

Reviewers: ,

Message:
please review

Description:
Clear fret-diagram- and harp-pedal-input-strings from whitespace

Whitespace-characters are deleted before further processing.

Allows for
\markup \fret-diagram #"s:2;h:5;
6-3;5-5;4-5;3-4;2-3;1-x;"

Also adding errors for typos in fret-diagram with a meaningful message:
\markup \fret-diagram #"s:2;g:5;
6-3;5-5;4-5;3-4;2-3;1-x;"
will return:
fatal error: Unhandled entry in fret-diagram: g:5

This error would not apply, if something for #\g would be defined
in fret-parse-definition-string somewhere in the future.

Something similiar is already in harp-pedals.scm

Please review this at https://codereview.appspot.com/257580043/

Affected files (+25, -3 lines):
  M scm/fret-diagrams.scm
  M scm/harp-pedals.scm
  M scm/lily-library.scm


Index: scm/fret-diagrams.scm
diff --git a/scm/fret-diagrams.scm b/scm/fret-diagrams.scm
index 041d180c04ddb6d624283e729b3937c1bc66274e..22d8eb33983cf0878da54f545110bbb877b01345 100644
--- a/scm/fret-diagrams.scm
+++ b/scm/fret-diagrams.scm
@@ -42,9 +42,19 @@ to end-point."
       (list new-value)
       (cons* new-value old-list)))

+(define (not-number-error input output)
+ "In order to give the user some help for correcting typos, throw an error with +a meaningful message, if an undefined character-option is used for @var{input}."
+  (if (not (string->number input))
+           (ly:error "Unhandled entry in fret-diagram: ~a"
+                     output)))
+
 (define (get-numeric-from-key keystring)
   "Get the numeric value from a key of the form k:val"
-  (string->number (substring keystring 2 (string-length keystring))))
+  (let ((entry (substring keystring 2 (string-length keystring))))
+    ;; throw an error, if `entry' can't be transformed into a number
+    (not-number-error entry keystring)
+    (string->number entry)))

 (define (numerify mylist)
   "Convert string values to numeric or character"
@@ -923,7 +933,9 @@ a fret-indication list with the appropriate values"
          (output-list '())
          (new-props '())
          (details (merge-details 'fret-diagram-details props '()))
-         (items (string-split definition-string #\;)))
+         ;; remove whitespace-characters from definition-string
+         (cleared-string (remove-white-space definition-string))
+         (items (string-split cleared-string #\;)))
     (let parse-item ((myitems items))
       (if (not (null? (cdr myitems)))
           (let ((test-string (car myitems)))
@@ -960,6 +972,9 @@ a fret-indication list with the appropriate values"
                              (acons 'dot-position dot-position details))))
               (else
                (let ((this-list (string-split test-string #\-)))
+ ;; throw an error, if an undefined character-option is used
+                 ;; for (car this-list)
+                 (not-number-error (car this-list) test-string)
                  (if (string->number (cadr this-list))
                      (set! output-list
                            (cons-fret
Index: scm/harp-pedals.scm
diff --git a/scm/harp-pedals.scm b/scm/harp-pedals.scm
index a6c93774d3a8a581af2666d5f67bf828ec4db495..45737cf1988c5c43fdb413c2f007b3470d761524 100644
--- a/scm/harp-pedals.scm
+++ b/scm/harp-pedals.scm
@@ -132,6 +132,7 @@ spacing after the divider).
            stencils)))

;; Parse the harp pedal definition string into list of directions (-1/0/1), #\o and #\| +;; Whitespace is removed from definition string before the procedure applies.
 (define (harp-pedals-parse-string definition-string)
"Parse a harp pedals diagram string and return a list containing 1, 0, -1, #\\o or #\\|"
   (map (lambda (c)
@@ -141,7 +142,7 @@ spacing after the divider).
            ((#\-) 0)
            ((#\| #\o) c)
            (else c)))
-       (string->list definition-string)))
+       (string->list (remove-white-space definition-string))))


 ;; Analyze the pedal-list: Return (pedalcount . (divider positions))
Index: scm/lily-library.scm
diff --git a/scm/lily-library.scm b/scm/lily-library.scm
index d413aceca5a3fb3dc670aec491f991a1b4355486..093ffee6c374c30e5813e985bb77f2c35ad55abc 100644
--- a/scm/lily-library.scm
+++ b/scm/lily-library.scm
@@ -786,6 +786,12 @@ as rectangular coordinates @ode{(x-length . y-length)}."
 (define-public (string-startswith s prefix)
(equal? prefix (substring s 0 (min (string-length s) (string-length prefix)))))

+(define-public (remove-white-space strg)
+"Remove characters satisfying @code{char-set:whitespace} from string @var{strg}"
+  (string-delete
+    strg
+    char-set:whitespace))
+
 (define-public (string-encode-integer i)
   (cond
    ((= i  0) "o")





reply via email to

[Prev in Thread] Current Thread [Next in Thread]