[racket] string-trim : an implementation & a question
This seems to be what I want the string-trim to do, but it seems that
all the string copying would be expensive. Is there a way to improve it
by avoiding the string copying?
My original inclination was to use a while loop with a test for
non-whitespace, but that appears to not be something scheme supports.
(define (string-trim s)
(let ( (l (string-length s) ) )
(cond
[ (= l 0) #f]
[ (char-whitespace? (string-ref s (- l 1) ) ) (string-trim
(substring s 0 (- l 1) ) ) ]
[else s]) ) )