diff --git a/GoldfishLang.tmu b/GoldfishLang.tmu index bcf2c936..2624ee38 100644 --- a/GoldfishLang.tmu +++ b/GoldfishLang.tmu @@ -1,4 +1,4 @@ -> +> > @@ -1519,9 +1519,9 @@ - + - + @@ -2021,6 +2021,50 @@ \; + rich-string> + + <\goldfish-chunk|goldfish/liii/lang.scm|true|true> + (define (%make-string) + + \ \ (rich-string (utf8-\>string (%to-bytevector)))) + + \; + + + + + 不可见的ASCII字符 + + <\goldfish-chunk|tests/goldfish/liii/lang-test.scm|true|true> + (check ($ #\\space :make-string) =\ " ") + + (check ($ #\\return :make-string) =\ (string #\\return)) + + \; + + + 普通的字母 + + <\goldfish-chunk|tests/goldfish/liii/lang-test.scm|true|true> + (check ($ #\\a :make-string) =\ "a") + + (check ($ #\\A :make-string) =\ "A") + + \; + + + ASCII范围外的字符:希腊字母、中文、表情符: + + <\goldfish-chunk|tests/goldfish/liii/lang-test.scm|true|true> + (check ((rich-char #xA3) :make-string) =\ "£") + + (check ((rich-char #x4E2D) :make-string) =\ "") + + (check ((rich-char #x1F600) :make-string) =\ "") + + \; + + \; @@ -2168,7 +2212,7 @@ \ \ \ \ \ \ \ \ ((and (case-class? v) (v :is-instance-of 'rich-char)) - \ \ \ \ \ \ \ \ \ ($ (v :to-string) :strip-prefix "#\\\\")) + \ \ \ \ \ \ \ \ \ (v :make-string)) \ \ \ \ \ \ \ \ (else (type-error "Expected types are char, rich-char, number, symbol or string")))) @@ -2188,6 +2232,8 @@ (check (rich-string :value-of (rich-char #x4E2D)) =\ "中") + (check (rich-string :value-of #\\ ) =\ " ") + \; diff --git a/goldfish/liii/lang.scm b/goldfish/liii/lang.scm index 3302f2f8..1ff9a06f 100644 --- a/goldfish/liii/lang.scm +++ b/goldfish/liii/lang.scm @@ -346,6 +346,9 @@ (object->string (integer->char code-point)) (string-append "#\\" (utf8->string (%to-bytevector))))) +(define (%make-string) + (rich-string (utf8->string (%to-bytevector)))) + ) (define make-rich-char rich-char) @@ -403,7 +406,7 @@ ((symbol? v) (rich-string (symbol->string v))) ((string? v) (rich-string v)) ((and (case-class? v) (v :is-instance-of 'rich-char)) - ($ (v :to-string) :strip-prefix "#\\")) + (v :make-string)) (else (type-error "Expected types are char, rich-char, number, symbol or string")))) (define (%get) data) diff --git a/tests/goldfish/liii/lang-test.scm b/tests/goldfish/liii/lang-test.scm index 938e9846..b432f2a0 100644 --- a/tests/goldfish/liii/lang-test.scm +++ b/tests/goldfish/liii/lang-test.scm @@ -310,12 +310,23 @@ (check ((rich-char #x1F600) :to-string) => "#\\😀") +(check ($ #\space :make-string) => " ") +(check ($ #\return :make-string) => (string #\return)) + +(check ($ #\a :make-string) => "a") +(check ($ #\A :make-string) => "A") + +(check ((rich-char #xA3) :make-string) => "£") +(check ((rich-char #x4E2D) :make-string) => "中") +(check ((rich-char #x1F600) :make-string) => "😀") + (check (rich-string :value-of #\a) => "a") (check (rich-string :value-of 'a) => "a") (check (rich-string :value-of 123) => "123") (check (rich-string :value-of 1.0) => "1.0") (check (rich-string :value-of "abc") => "abc") (check (rich-string :value-of (rich-char #x4E2D)) => "中") +(check (rich-string :value-of #\ ) => " ") (check ($ "abc" :get) => "abc") (check ($ "" :get) => "")