Reorganize, fix a bug with string shared

This commit is contained in:
Vivianne 2024-03-02 13:59:31 -05:00
parent 470b20a74c
commit 5b440bbb64
3 changed files with 24 additions and 12 deletions

View File

@ -22,10 +22,14 @@
((directory
"runewidth"
((scheme-file "emoji")
(directory "eastasian"
((scheme-file "locale")))
(scheme-file "eastasian")
(scheme-file "internal")))
(scheme-file "runewidth")))
(tests ((directory "tests" ((scheme-file "test-posix")))))
(tests ((directory
"tests"
((scheme-file "test-eastasian-locale")))))
(programs
((directory
"scripts"
@ -40,5 +44,4 @@
(infrastructure
((scheme-file "guix")
(text-file ".gitignore")
(scheme-file "hall")
(directory "tests" ((scheme-file "test-posix")))))))
(scheme-file "hall")))))

View File

@ -1,6 +1,6 @@
(define-module (runewidth posix)
(define-module (runewidth eastasian locale)
#:use-module (ice-9 regex)
#:export (east-asian?))
#:export (eastasian-locale?))
(define wide-locales
(list
@ -36,7 +36,7 @@
(getenv "LANG")
""))
(define* (east-asian? #:optional (locale (get-env-locale)))
(define* (eastasian-locale? #:optional (locale (get-env-locale)))
"Check if a given locale (or the currently installed locale from the environment) is considered an east asian locale"
(unless (string? locale)
(error "`locale' must be a string"))
@ -52,13 +52,19 @@
(match:substring locale-match 2)))
locale)))
(pk locale)
(pk charset)
(and
(not (regexp-exec c-or-posix-regexp locale))
(not (string-suffix? "@cjk_narrow" charset))
(let ((index-@ (string-index charset #\@)))
;; strip @foo from the end of the charset
(when index-@
(set! charset (substring/shared charset 0 index-@)))
(set! charset (substring charset 0 index-@)))
(pk charset)
(pk locale)
(and (member charset wide-locales)
(or

View File

@ -1,11 +1,14 @@
(define-module (tests test-posix)
#:use-module (runewidth posix)
(define-module (tests test-eastasian-locale)
#:use-module (runewidth eastasian locale)
#:use-module (srfi srfi-64))
(test-begin "test-posix")
(test-begin "test-eastasian-locale")
(define (test-east expected charset)
(test-equal expected (east-asian? charset)))
(test-equal
(format #f "check ~a" charset)
expected
(eastasian-locale? charset)))
(define data
'((#f "foo@cjk_narrow")
@ -20,4 +23,4 @@
(for-each (λ (p) (apply test-east p)) data)
(test-end "test-posix")
(test-end "test-eastasian-locale")