mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-12 15:37:35 +02:00
string[-ci]<>=? are also n-ary
This commit is contained in:
parent
544b6a50c5
commit
e701c63762
3 changed files with 34 additions and 21 deletions
|
@ -419,17 +419,23 @@
|
|||
(define (string . args) (list->string args))
|
||||
(define (string-append . args) (string-concatenate args))
|
||||
|
||||
(define (string=? s1 s2) (eq? (string-cmp s1 s2 #f) 0))
|
||||
(define (string<? s1 s2) (< (string-cmp s1 s2 #f) 0))
|
||||
(define (string<=? s1 s2) (<= (string-cmp s1 s2 #f) 0))
|
||||
(define (string>? s1 s2) (> (string-cmp s1 s2 #f) 0))
|
||||
(define (string>=? s1 s2) (>= (string-cmp s1 s2 #f) 0))
|
||||
(define (string-cmp-ls op ci? s ls)
|
||||
(if (null? ls)
|
||||
#t
|
||||
(and (op (string-cmp s (car ls) ci?) 0)
|
||||
(string-cmp-ls op ci? (car ls) (cdr ls)))))
|
||||
|
||||
(define (string-ci=? s1 s2) (eq? (string-cmp s1 s2 #t) 0))
|
||||
(define (string-ci<? s1 s2) (< (string-cmp s1 s2 #t) 0))
|
||||
(define (string-ci<=? s1 s2) (<= (string-cmp s1 s2 #t) 0))
|
||||
(define (string-ci>? s1 s2) (> (string-cmp s1 s2 #t) 0))
|
||||
(define (string-ci>=? s1 s2) (>= (string-cmp s1 s2 #t) 0))
|
||||
(define (string=? s . ls) (string-cmp-ls eq? #f s ls))
|
||||
(define (string<? s . ls) (string-cmp-ls < #f s ls))
|
||||
(define (string>? s . ls) (string-cmp-ls > #f s ls))
|
||||
(define (string<=? s . ls) (string-cmp-ls <= #f s ls))
|
||||
(define (string>=? s . ls) (string-cmp-ls >= #f s ls))
|
||||
|
||||
(define (string-ci=? s . ls) (string-cmp-ls eq? #t s ls))
|
||||
(define (string-ci<? s . ls) (string-cmp-ls < #t s ls))
|
||||
(define (string-ci>? s . ls) (string-cmp-ls > #t s ls))
|
||||
(define (string-ci<=? s . ls) (string-cmp-ls <= #t s ls))
|
||||
(define (string-ci>=? s . ls) (string-cmp-ls >= #t s ls))
|
||||
|
||||
;; list utils
|
||||
|
||||
|
|
|
@ -71,8 +71,15 @@
|
|||
(define (string-foldcase str)
|
||||
(string-map char-foldcase str))
|
||||
|
||||
(define (string-ci<=? a b) (string<=? (string-foldcase a) (string-foldcase b)))
|
||||
(define (string-ci<? a b) (string<? (string-foldcase a) (string-foldcase b)))
|
||||
(define (string-ci=? a b) (string=? (string-foldcase a) (string-foldcase b)))
|
||||
(define (string-ci>=? a b) (string>=? (string-foldcase a) (string-foldcase b)))
|
||||
(define (string-ci>? a b) (string>? (string-foldcase a) (string-foldcase b)))
|
||||
(define (string-cmp-ci op a ls)
|
||||
(let lp ((op op) (a (string-foldcase a)) (ls ls))
|
||||
(if (null? ls)
|
||||
#t
|
||||
(let ((b (string-foldcase (car ls))))
|
||||
(and (op a b) (lp op b (cdr ls)))))))
|
||||
|
||||
(define (string-ci=? a . ls) (string-cmp-ci string=? a ls))
|
||||
(define (string-ci<? a . ls) (string-cmp-ci string<? a ls))
|
||||
(define (string-ci>? a . ls) (string-cmp-ci string>? a ls))
|
||||
(define (string-ci<=? a . ls) (string-cmp-ci string<=? a ls))
|
||||
(define (string-ci>=? a . ls) (string-cmp-ci string>=? a ls))
|
||||
|
|
|
@ -980,32 +980,32 @@
|
|||
(test "a-c" (let ((str (string #\a #\b #\c))) (string-set! str 1 #\-) str))
|
||||
|
||||
(test #t (string=? "" ""))
|
||||
(test #t (string=? "abc" "abc"))
|
||||
(test #t (string=? "abc" "abc" "abc"))
|
||||
(test #f (string=? "" "abc"))
|
||||
(test #f (string=? "abc" "aBc"))
|
||||
|
||||
(test #f (string<? "" ""))
|
||||
(test #f (string<? "abc" "abc"))
|
||||
(test #t (string<? "abc" "abcd"))
|
||||
(test #t (string<? "abc" "abcd" "acd"))
|
||||
(test #f (string<? "abcd" "abc"))
|
||||
(test #t (string<? "abc" "bbc"))
|
||||
|
||||
(test #f (string>? "" ""))
|
||||
(test #f (string>? "abc" "abc"))
|
||||
(test #f (string>? "abc" "abcd"))
|
||||
(test #t (string>? "abcd" "abc"))
|
||||
(test #t (string>? "acd" "abcd" "abc"))
|
||||
(test #f (string>? "abc" "bbc"))
|
||||
|
||||
(test #t (string<=? "" ""))
|
||||
(test #t (string<=? "abc" "abc"))
|
||||
(test #t (string<=? "abc" "abcd"))
|
||||
(test #t (string<=? "abc" "abcd" "abcd"))
|
||||
(test #f (string<=? "abcd" "abc"))
|
||||
(test #t (string<=? "abc" "bbc"))
|
||||
|
||||
(test #t (string>=? "" ""))
|
||||
(test #t (string>=? "abc" "abc"))
|
||||
(test #f (string>=? "abc" "abcd"))
|
||||
(test #t (string>=? "abcd" "abc"))
|
||||
(test #t (string>=? "abcd" "abcd" "abc"))
|
||||
(test #f (string>=? "abc" "bbc"))
|
||||
|
||||
(test #t (string-ci=? "" ""))
|
||||
|
@ -1030,7 +1030,7 @@
|
|||
(test #f (string-ci>=? "abc" "aBcD"))
|
||||
(test #t (string-ci>=? "ABCd" "aBc"))
|
||||
|
||||
(test #t (string-ci=? "ΑΒΓ" "αβγ"))
|
||||
(test #t (string-ci=? "ΑΒΓ" "αβγ" "αβγ"))
|
||||
(test #f (string-ci<? "ΑΒΓ" "αβγ"))
|
||||
(test #f (string-ci>? "ΑΒΓ" "αβγ"))
|
||||
(test #t (string-ci<=? "ΑΒΓ" "αβγ"))
|
||||
|
|
Loading…
Add table
Reference in a new issue