string
string*
string->list
+ string->nfd
string->vector
string-any
string-append
string-ci>?
string-compare
string-compare-ci
+ string-canonical-foldcase
string-copy
string-copy!
string-count
char-set:changes-when-case-folded
ucd-nt-value)
(export (runtime ustring)
+ char-changes-when-case-folded?
char-changes-when-lower-cased?
char-changes-when-upper-cased?
char-nfd-quick-check?
(if (ascii-string? string)
;; Needed during cold load.
(%legacy-string->bytevector (ascii-string-foldcase string))
- (string->utf8 (string-foldcase string))))
+ (string->utf8 (string-canonical-foldcase string))))
(define (ascii-string? string)
(and (legacy-string? string)
(loop (fix:+ index 1))))))))
(define (string-lower-case? string)
- (let* ((nfd (string->nfd string))
- (end (string-length nfd)))
+ (nfd-string-lower-case? (string->nfd string)))
+
+(define (string-upper-case? string)
+ (nfd-string-upper-case? (string->nfd string)))
+
+(define (nfd-string-lower-case? nfd)
+ (let ((end (string-length nfd)))
(let loop ((i 0))
(if (fix:< i end)
(and (not (char-changes-when-lower-cased? (string-ref nfd i)))
(loop (fix:+ i 1)))
#t))))
-(define (string-upper-case? string)
- (let* ((nfd (string->nfd string))
- (end (string-length nfd)))
+(define (nfd-string-upper-case? nfd)
+ (let ((end (string-length nfd)))
(let loop ((i 0))
(if (fix:< i end)
(and (not (char-changes-when-upper-cased? (string-ref nfd i)))
(loop (fix:+ i 1)))
#t))))
+
+(define (nfd-string-case-folded? nfd)
+ (let ((end (string-length nfd)))
+ (let loop ((i 0))
+ (if (fix:< i end)
+ (and (not (char-changes-when-case-folded? (string-ref nfd i)))
+ (loop (fix:+ i 1)))
+ #t))))
+
+(define (string-canonical-foldcase string)
+ (let ((nfd (string->nfd string)))
+ (if (nfd-string-case-folded? nfd)
+ nfd
+ (string->nfd (string-foldcase string)))))
\f
;;;; Normalization