Parse a string containing a measurement, e.g., "3pi" or "2.5in", and return the magnitude and units: (3 "pi") or (2.5 "in").
Either element of the list may be #f if the string cannot reasonably be parsed as a measurement. Leading and trailing spaces are ignored.
(define (parse-measurement measure) ;; Parse a string containing a measurement and return the magnitude and units (let* ((magstart (find-first-char measure " " "0123456789.")) (unitstart (find-first-char measure " 0123456789." "")) (unitend (find-first-char measure "" " " unitstart)) (magnitude (if (< magstart 0) #f (if (< unitstart 0) (substring measure magstart (string-length measure)) (substring measure magstart unitstart)))) (unit (if (< unitstart 0) #f (if (< unitend 0) (substring measure unitstart (string-length measure)) (substring measure unitstart unitend))))) (list magnitude unit)))