2007-05-05 04:45:13 -04:00
|
|
|
|
|
|
|
(library (ikarus chars)
|
2007-10-12 02:59:27 -04:00
|
|
|
(export char=? char<? char<=? char>? char>=? char->integer integer->char)
|
2007-05-05 04:45:13 -04:00
|
|
|
(import
|
2007-05-05 05:14:24 -04:00
|
|
|
(except (ikarus)
|
2007-10-12 02:59:27 -04:00
|
|
|
char=? char<? char<=? char>? char>=? integer->char char->integer)
|
2007-05-06 17:58:34 -04:00
|
|
|
(ikarus system $pairs)
|
|
|
|
(ikarus system $chars)
|
|
|
|
(ikarus system $fx))
|
2007-05-05 04:45:13 -04:00
|
|
|
|
2007-05-05 06:36:38 -04:00
|
|
|
(define integer->char
|
|
|
|
(lambda (n)
|
2007-05-19 15:18:08 -04:00
|
|
|
(cond
|
|
|
|
[(not (fixnum? n)) (error 'integer->char "invalid argument ~s" n)]
|
|
|
|
[($fx< n 0) (error 'integer->char "~s is negative" n)]
|
|
|
|
[($fx<= n #xD7FF) ($fixnum->char n)]
|
|
|
|
[($fx< n #xE000)
|
|
|
|
(error 'integer->char "~s does not have a unicode representation" n)]
|
|
|
|
[($fx<= n #x10FFFF) ($fixnum->char n)]
|
|
|
|
[else (error 'integer->char
|
|
|
|
"~s does not have a unicode representation" n)])))
|
2007-05-05 06:36:38 -04:00
|
|
|
|
|
|
|
(define char->integer
|
|
|
|
(lambda (x)
|
|
|
|
(unless (char? x)
|
|
|
|
(error 'char->integer "~s is not a character" x))
|
|
|
|
($char->fixnum x)))
|
|
|
|
|
2007-05-05 04:45:13 -04:00
|
|
|
;;; FIXME: this file is embarrasing
|
|
|
|
(define char=?
|
|
|
|
(let ()
|
|
|
|
(define (err x)
|
|
|
|
(error 'char=? "~s is not a character" x))
|
|
|
|
(case-lambda
|
|
|
|
[(c1 c2)
|
|
|
|
(if (char? c1)
|
|
|
|
(if (char? c2)
|
|
|
|
($char= c1 c2)
|
|
|
|
(err c2))
|
|
|
|
(err c1))]
|
|
|
|
[(c1 c2 c3)
|
|
|
|
(if (char? c1)
|
|
|
|
(if (char? c2)
|
|
|
|
(if (char? c3)
|
|
|
|
(and ($char= c1 c2)
|
|
|
|
($char= c2 c3))
|
|
|
|
(err c3))
|
|
|
|
(err c2))
|
|
|
|
(err c1))]
|
|
|
|
[(c1 . c*)
|
|
|
|
(if (char? c1)
|
|
|
|
(let f ([c* c*])
|
|
|
|
(or (null? c*)
|
|
|
|
(let ([c2 ($car c*)])
|
|
|
|
(if (char? c2)
|
|
|
|
(if ($char= c1 c2)
|
|
|
|
(f ($cdr c*))
|
|
|
|
(let g ([c* ($cdr c*)])
|
|
|
|
(if (null? c*)
|
|
|
|
#f
|
|
|
|
(if (char? ($car c*))
|
|
|
|
(g ($cdr c*))
|
|
|
|
(err ($car c*))))))
|
|
|
|
(err c2)))))
|
|
|
|
(err c1))])))
|
|
|
|
|
|
|
|
(define char<?
|
|
|
|
(let ()
|
|
|
|
(define (err x)
|
|
|
|
(error 'char<? "~s is not a character" x))
|
|
|
|
(case-lambda
|
|
|
|
[(c1 c2)
|
|
|
|
(if (char? c1)
|
|
|
|
(if (char? c2)
|
|
|
|
($char< c1 c2)
|
|
|
|
(err c2))
|
|
|
|
(err c1))]
|
|
|
|
[(c1 c2 c3)
|
|
|
|
(if (char? c1)
|
|
|
|
(if (char? c2)
|
|
|
|
(if (char? c3)
|
|
|
|
(and ($char< c1 c2)
|
|
|
|
($char< c2 c3))
|
|
|
|
(err c3))
|
|
|
|
(err c2))
|
|
|
|
(err c1))]
|
|
|
|
[(c1 . c*)
|
|
|
|
(if (char? c1)
|
|
|
|
(let f ([c1 c1] [c* c*])
|
|
|
|
(or (null? c*)
|
|
|
|
(let ([c2 ($car c*)])
|
|
|
|
(if (char? c2)
|
|
|
|
(if ($char< c1 c2)
|
|
|
|
(f c2 ($cdr c*))
|
|
|
|
(let g ([c* ($cdr c*)])
|
|
|
|
(if (null? c*)
|
|
|
|
#f
|
|
|
|
(if (char? ($car c*))
|
|
|
|
(g ($cdr c*))
|
|
|
|
(err ($car c*))))))
|
|
|
|
(err c2)))))
|
|
|
|
(err c1))])))
|
|
|
|
|
|
|
|
(define char<=?
|
|
|
|
(let ()
|
|
|
|
(define (err x)
|
|
|
|
(error 'char<=? "~s is not a character" x))
|
|
|
|
(case-lambda
|
|
|
|
[(c1 c2)
|
|
|
|
(if (char? c1)
|
|
|
|
(if (char? c2)
|
|
|
|
($char<= c1 c2)
|
|
|
|
(err c2))
|
|
|
|
(err c1))]
|
|
|
|
[(c1 c2 c3)
|
|
|
|
(if (char? c1)
|
|
|
|
(if (char? c2)
|
|
|
|
(if (char? c3)
|
|
|
|
(and ($char<= c1 c2)
|
|
|
|
($char<= c2 c3))
|
|
|
|
(err c3))
|
|
|
|
(err c2))
|
|
|
|
(err c1))]
|
|
|
|
[(c1 . c*)
|
|
|
|
(if (char? c1)
|
|
|
|
(let f ([c1 c1] [c* c*])
|
|
|
|
(or (null? c*)
|
|
|
|
(let ([c2 ($car c*)])
|
|
|
|
(if (char? c2)
|
|
|
|
(if ($char<= c1 c2)
|
|
|
|
(f c2 ($cdr c*))
|
|
|
|
(let g ([c* ($cdr c*)])
|
|
|
|
(if (null? c*)
|
|
|
|
#f
|
|
|
|
(if (char? ($car c*))
|
|
|
|
(g ($cdr c*))
|
|
|
|
(err ($car c*))))))
|
|
|
|
(err c2)))))
|
|
|
|
(err c1))])))
|
|
|
|
|
|
|
|
(define char>?
|
|
|
|
(let ()
|
|
|
|
(define (err x)
|
|
|
|
(error 'char>? "~s is not a character" x))
|
|
|
|
(case-lambda
|
|
|
|
[(c1 c2)
|
|
|
|
(if (char? c1)
|
|
|
|
(if (char? c2)
|
|
|
|
($char> c1 c2)
|
|
|
|
(err c2))
|
|
|
|
(err c1))]
|
|
|
|
[(c1 c2 c3)
|
|
|
|
(if (char? c1)
|
|
|
|
(if (char? c2)
|
|
|
|
(if (char? c3)
|
|
|
|
(and ($char> c1 c2)
|
|
|
|
($char> c2 c3))
|
|
|
|
(err c3))
|
|
|
|
(err c2))
|
|
|
|
(err c1))]
|
|
|
|
[(c1 . c*)
|
|
|
|
(if (char? c1)
|
|
|
|
(let f ([c1 c1] [c* c*])
|
|
|
|
(or (null? c*)
|
|
|
|
(let ([c2 ($car c*)])
|
|
|
|
(if (char? c2)
|
|
|
|
(if ($char> c1 c2)
|
|
|
|
(f c2 ($cdr c*))
|
|
|
|
(let g ([c* ($cdr c*)])
|
|
|
|
(if (null? c*)
|
|
|
|
#f
|
|
|
|
(if (char? ($car c*))
|
|
|
|
(g ($cdr c*))
|
|
|
|
(err ($car c*))))))
|
|
|
|
(err c2)))))
|
|
|
|
(err c1))])))
|
|
|
|
|
|
|
|
(define char>=?
|
|
|
|
(let ()
|
|
|
|
(define (err x)
|
|
|
|
(error 'char>=? "~s is not a character" x))
|
|
|
|
(case-lambda
|
|
|
|
[(c1 c2)
|
|
|
|
(if (char? c1)
|
|
|
|
(if (char? c2)
|
|
|
|
($char>= c1 c2)
|
|
|
|
(err c2))
|
|
|
|
(err c1))]
|
|
|
|
[(c1 c2 c3)
|
|
|
|
(if (char? c1)
|
|
|
|
(if (char? c2)
|
|
|
|
(if (char? c3)
|
|
|
|
(and ($char>= c1 c2)
|
|
|
|
($char>= c2 c3))
|
|
|
|
(err c3))
|
|
|
|
(err c2))
|
|
|
|
(err c1))]
|
|
|
|
[(c1 . c*)
|
|
|
|
(if (char? c1)
|
|
|
|
(let f ([c1 c1] [c* c*])
|
|
|
|
(or (null? c*)
|
|
|
|
(let ([c2 ($car c*)])
|
|
|
|
(if (char? c2)
|
|
|
|
(if ($char>= c1 c2)
|
|
|
|
(f c2 ($cdr c*))
|
|
|
|
(let g ([c* ($cdr c*)])
|
|
|
|
(if (null? c*)
|
|
|
|
#f
|
|
|
|
(if (char? ($car c*))
|
|
|
|
(g ($cdr c*))
|
|
|
|
(err ($car c*))))))
|
|
|
|
(err c2)))))
|
|
|
|
(err c1))])))
|
2007-05-05 05:14:24 -04:00
|
|
|
|
2007-09-13 06:27:31 -04:00
|
|
|
|
2007-05-05 04:45:13 -04:00
|
|
|
)
|