Added char-foldcase and char-ci predicates

This commit is contained in:
Justin Ethier 2016-03-31 22:23:07 -04:00
parent f671d85ce6
commit 489389a3ee

View file

@ -10,16 +10,25 @@
(export (export
char-alphabetic? char-alphabetic?
char-downcase char-downcase
char-foldcase
char-lower-case? char-lower-case?
char-numeric? char-numeric?
char-upcase char-upcase
char-upper-case? char-upper-case?
char-whitespace? char-whitespace?
char-ci<=?
char-ci<?
char-ci=?
char-ci>=?
char-ci>?
digit-value digit-value
string-upcase string-upcase
string-downcase string-downcase
; TODO: ; TODO:
;string-foldcase ;string-foldcase
;string-ci<=? string-ci<?
;string-ci=? string-ci>=?
;string-ci>?
) )
(import (scheme base)) (import (scheme base))
(begin (begin
@ -37,7 +46,12 @@
(- (char->integer #\a) (- (char->integer #\a)
(char->integer #\A)))) (char->integer #\A))))
c)) c))
; TODO: char-foldcase (define char-foldcase char-downcase) ;; Good enough for now, since no Unicode yet
(define (char-ci=? c1 c2 . cs) (apply char=? (map char-foldcase (cons c1 (cons c2 cs)))))
(define (char-ci<=? c1 c2 . cs) (apply char<=? (map char-foldcase (cons c1 (cons c2 cs)))))
(define (char-ci<? c1 c2 . cs) (apply char<? (map char-foldcase (cons c1 (cons c2 cs)))))
(define (char-ci>=? c1 c2 . cs) (apply char>=? (map char-foldcase (cons c1 (cons c2 cs)))))
(define (char-ci>? c1 c2 . cs) (apply char>? (map char-foldcase (cons c1 (cons c2 cs)))))
(define (char-alphabetic? c) (or (char-upper-case? c) (char-lower-case? c))) (define (char-alphabetic? c) (or (char-upper-case? c) (char-lower-case? c)))
(define (char-upper-case? c) (and (char>=? c #\A) (char<=? c #\Z))) ;; ASCII-only (define (char-upper-case? c) (and (char>=? c #\A) (char<=? c #\Z))) ;; ASCII-only
(define (char-lower-case? c) (and (char>=? c #\a) (char<=? c #\z))) ;; ASCII-only (define (char-lower-case? c) (and (char>=? c #\a) (char<=? c #\z))) ;; ASCII-only