aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/text/encoding.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/data/text/encoding.lux')
-rw-r--r--stdlib/source/lux/data/text/encoding.lux29
1 files changed, 24 insertions, 5 deletions
diff --git a/stdlib/source/lux/data/text/encoding.lux b/stdlib/source/lux/data/text/encoding.lux
index 2752903a7..e4d24f709 100644
--- a/stdlib/source/lux/data/text/encoding.lux
+++ b/stdlib/source/lux/data/text/encoding.lux
@@ -9,7 +9,7 @@
abstract]
[world
[binary (#+ Binary)]]
- [host (#+ import:)]])
+ ["." host]])
## https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html
@@ -171,14 +171,25 @@
(|>> :representation))
)
-(with-expansions [<for-jvm> (as-is (import: #long java/lang/String
+(with-expansions [<for-jvm> (as-is (host.import: #long java/lang/String
(new [[byte] java/lang/String])
(getBytes [java/lang/String] [byte])))]
(`` (for {(~~ (static @.old))
(as-is <for-jvm>)
(~~ (static @.jvm))
- (as-is <for-jvm>)})))
+ (as-is <for-jvm>)
+
+ (~~ (static @.js))
+ (as-is (host.import: Uint8Array)
+
+ (host.import: TextEncoder
+ (new [host.String])
+ (encode [host.String] Uint8Array))
+
+ (host.import: TextDecoder
+ (new [host.String])
+ (decode [Uint8Array] host.String)))})))
(def: #export (to-utf8 value)
(-> Text Binary)
@@ -190,7 +201,11 @@
(:coerce java/lang/String value))
(~~ (static @.jvm))
- (java/lang/String::getBytes (..name ..utf-8) value)})))
+ (java/lang/String::getBytes (..name ..utf-8) value)
+
+ (~~ (static @.js))
+ (|> (TextEncoder::new [(..name ..utf-8)])
+ (TextEncoder::encode [value]))})))
(def: #export (from-utf8 value)
(-> Binary (Error Text))
@@ -198,7 +213,11 @@
(#error.Success (java/lang/String::new value (..name ..utf-8)))
(~~ (static @.jvm))
- (#error.Success (java/lang/String::new value (..name ..utf-8)))})))
+ (#error.Success (java/lang/String::new value (..name ..utf-8)))
+
+ (~~ (static @.js))
+ (#error.Success (|> (TextDecoder::new [(..name ..utf-8)])
+ (TextDecoder::decode [value])))})))
(structure: #export UTF-8 (Codec Binary Text)
(def: encode ..to-utf8)