diff options
Diffstat (limited to 'stdlib/source/lux/data/text/encoding.lux')
-rw-r--r-- | stdlib/source/lux/data/text/encoding.lux | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/stdlib/source/lux/data/text/encoding.lux b/stdlib/source/lux/data/text/encoding.lux index 2050cbc8c..55afc77ed 100644 --- a/stdlib/source/lux/data/text/encoding.lux +++ b/stdlib/source/lux/data/text/encoding.lux @@ -7,7 +7,7 @@ [control ["." try (#+ Try)]] [data - [binary (#+ Binary)]] + ["." binary (#+ Binary)]] [type abstract]]) @@ -195,7 +195,7 @@ (decode [Uint8Array] host.String)))} (as_is))) -(def: (to_utf8 value) +(def: (utf8\encode value) (-> Text Binary) (for {@.old (java/lang/String::getBytes (..name ..utf_8) @@ -224,9 +224,12 @@ ) @.python - (:coerce Binary ("python apply" (:assume ("python constant" "bytearray")) value "utf-8"))})) + (:coerce Binary ("python apply" (:assume ("python constant" "bytearray")) value "utf-8"))} -(def: (from_utf8 value) + ## Default + ("lua utf8 encode" value))) + +(def: (utf8\decode value) (-> Binary (Try Text)) (with_expansions [<jvm> (#try.Success (java/lang/String::new value (..name ..utf_8)))] (for {@.old <jvm> @@ -249,10 +252,13 @@ #try.Success)) @.python - (host.try (:coerce Text ("python object do" "decode" (:assume value) "utf-8")))}))) + (host.try (:coerce Text ("python object do" "decode" (:assume value) "utf-8")))} + + ## Default + (#try.Success ("lua utf8 decode" value))))) (structure: #export utf8 (Codec Binary Text) - (def: encode ..to_utf8) - (def: decode ..from_utf8)) + (def: encode ..utf8\encode) + (def: decode ..utf8\decode)) |