Move simplified string-utf8? to util-utf8.

This commit is contained in:
Dominik Pantůček 2023-06-24 22:05:20 +02:00
parent 0b383c6fa6
commit 06746c1c40
4 changed files with 12 additions and 11 deletions

View file

@ -44,6 +44,8 @@
utf8-string->list
list->utf8-string
string-utf8?
util-utf8-tests!
)
@ -272,6 +274,12 @@
(loop (cdr lst)
(prepend-unicode-char-to-utf8-list (car lst) res)))))
;; Returns true, if given string contains UTF-8 characters
(define (string-utf8? s)
(let ((asciilen (string-length s))
(utf8len (utf8-string-length s)))
(not (= asciilen utf8len))))
;; Module self-tests
(define (util-utf8-tests!)
(run-tests
@ -303,6 +311,8 @@
(test-equal? utf8-string-next-char
(utf8-string-next-char "ěščř" 2)
4)
(test-true string-utf8? (string-utf8? "ěščř"))
(test-false string-utf8? (string-utf8? "Hello World!"))
))
)