~ chicken-core (chicken-5) 21916d854289dd25151eea3286f98a86817748be
commit 21916d854289dd25151eea3286f98a86817748be
Author: Peter Bex <peter@more-magic.net>
AuthorDate: Fri Oct 21 15:21:08 2022 +0200
Commit: Peter Bex <peter@more-magic.net>
CommitDate: Fri Oct 21 15:21:08 2022 +0200
Fix string-trim for edge case of 1 char-long result
Single-character strings would be shortened to the empty string.
diff --git a/batch-driver.scm b/batch-driver.scm
index dfed3aaa..0b3d7e02 100644
--- a/batch-driver.scm
+++ b/batch-driver.scm
@@ -285,14 +285,14 @@
xs) ) )
(define (string-trim str)
- (let loop ((front 0)
- (back (sub1 (string-length str))))
- (cond ((= front back) "")
- ((char-whitespace? (string-ref str front))
- (loop (add1 front) back))
- ((char-whitespace? (string-ref str back))
- (loop front (sub1 back)))
- (else (substring str front (add1 back))))))
+ (let loop ((front 0)
+ (back (string-length str)))
+ (cond ((= front back) "")
+ ((char-whitespace? (string-ref str front))
+ (loop (add1 front) back))
+ ((char-whitespace? (string-ref str (sub1 back)))
+ (loop front (sub1 back)))
+ (else (substring str front back)))))
(define (string->extension-name str)
(let ((str (string-trim str)))
diff --git a/csi.scm b/csi.scm
index 18498194..dcd67594 100644
--- a/csi.scm
+++ b/csi.scm
@@ -974,14 +974,14 @@ EOF
'("-D" "-feature" "-I" "-include-path" "-K" "-keyword-style" "-no-feature") )
(define (string-trim str)
- (let loop ((front 0)
- (back (sub1 (string-length str))))
+ (let loop ((front 0)
+ (back (string-length str)))
(cond ((= front back) "")
- ((char-whitespace? (string-ref str front))
- (loop (add1 front) back))
- ((char-whitespace? (string-ref str back))
- (loop front (sub1 back)))
- (else (substring str front (add1 back))))))
+ ((char-whitespace? (string-ref str front))
+ (loop (add1 front) back))
+ ((char-whitespace? (string-ref str (sub1 back)))
+ (loop front (sub1 back)))
+ (else (substring str front back)))))
(define (string->extension-name str)
(let ((str (string-trim str)))
Trap