~ chicken-core (chicken-5) 32d0deac00795122cc03146c04523a7145ac626a
commit 32d0deac00795122cc03146c04523a7145ac626a
Author: Mario Domenech Goulart <address@hidden>
AuthorDate: Sat Jan 11 18:11:47 2014 -0200
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Tue Jan 28 09:16:05 2014 +0100
Fix bug in string-index-right and string-skip-right
Patch by David Van Horn to the SRFI-13 mailing list (see
http://srfi.schemers.org/srfi-13/post-mail-archive/msg00007.html).
Ported to CHICKEN by Seth Alves (see
http://lists.nongnu.org/archive/html/chicken-hackers/2014-01/msg00022.html).
Signed-off-by: Evan Hanson <address@hidden>
diff --git a/srfi-13.scm b/srfi-13.scm
index 7b161532..876a2bda 100644
--- a/srfi-13.scm
+++ b/srfi-13.scm
@@ -1208,17 +1208,17 @@
(let-string-start+end (start end) string-index-right str maybe-start+end
(cond ((char? criteria)
(let lp ((i (- end 1)))
- (and (>= i 0)
+ (and (>= i start)
(if (char=? criteria (string-ref str i)) i
(lp (- i 1))))))
((char-set? criteria)
(let lp ((i (- end 1)))
- (and (>= i 0)
+ (and (>= i start)
(if (char-set-contains? criteria (string-ref str i)) i
(lp (- i 1))))))
((procedure? criteria)
(let lp ((i (- end 1)))
- (and (>= i 0)
+ (and (>= i start)
(if (criteria (string-ref str i)) i
(lp (- i 1))))))
(else (##sys#error 'string-index-right "Second param is neither char-set, char, or predicate procedure."
@@ -1250,19 +1250,19 @@
(let-string-start+end (start end) string-skip-right str maybe-start+end
(cond ((char? criteria)
(let lp ((i (- end 1)))
- (and (>= i 0)
+ (and (>= i start)
(if (char=? criteria (string-ref str i))
(lp (- i 1))
i))))
((char-set? criteria)
(let lp ((i (- end 1)))
- (and (>= i 0)
+ (and (>= i start)
(if (char-set-contains? criteria (string-ref str i))
(lp (- i 1))
i))))
((procedure? criteria)
(let lp ((i (- end 1)))
- (and (>= i 0)
+ (and (>= i start)
(if (criteria (string-ref str i)) (lp (- i 1))
i))))
(else (##sys#error 'string-skip-right "CRITERIA param is neither char-set or char."
diff --git a/tests/srfi-13-tests.scm b/tests/srfi-13-tests.scm
index 29d6b80b..a9735cc6 100644
--- a/tests/srfi-13-tests.scm
+++ b/tests/srfi-13-tests.scm
@@ -688,3 +688,21 @@
(handle-exceptions exn
(k #f)
(string=? "abrcaaba" (string-delete char-set:upper-case "abrAcaDabRa"))))))
+
+
+; http://srfi.schemers.org/srfi-13/post-mail-archive/msg00007.html
+; From: David Van Horn <address@hidden>
+; Date: Wed, 01 Nov 2006 07:53:34 +0100
+;
+; Both string-index-right and string-skip-right will continue to search
+; left past a given start index.
+;
+; (string-index-right "abbb" #\a 1) ;; => 0, but should be #f
+; (string-skip-right "abbb" #\b 1) ;; => 0, but should be #f
+;
+; This also causes incorrect results for string-trim-right,
+; string-trim-both and string-tokenize when given a non-zero start
+; argument.
+
+(test "string-index-right" #f (string-index-right "abbb" #\a 1))
+(test "string-skip-right" #f (string-skip-right "abbb" #\b 1))
Trap