aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/text/encoding.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/data/text/encoding.lux37
1 files changed, 30 insertions, 7 deletions
diff --git a/stdlib/source/lux/data/text/encoding.lux b/stdlib/source/lux/data/text/encoding.lux
index 55afc77ed..88bbea138 100644
--- a/stdlib/source/lux/data/text/encoding.lux
+++ b/stdlib/source/lux/data/text/encoding.lux
@@ -192,7 +192,16 @@
(host.import: TextDecoder
(new [host.String])
- (decode [Uint8Array] host.String)))}
+ (decode [Uint8Array] host.String)))
+
+ @.ruby
+ (as_is (host.import: String #as RubyString
+ (encode [Text] RubyString)
+ (force_encoding [Text] Text)
+ (bytes [] Binary))
+
+ (host.import: Array #as RubyArray
+ (pack [Text] RubyString)))}
(as_is)))
(def: (utf8\encode value)
@@ -224,10 +233,16 @@
)
@.python
- (:coerce Binary ("python apply" (:assume ("python constant" "bytearray")) value "utf-8"))}
+ (:coerce Binary ("python apply" (:assume ("python constant" "bytearray")) value "utf-8"))
- ## Default
- ("lua utf8 encode" value)))
+ @.lua
+ ("lua utf8 encode" value)
+
+ @.ruby
+ (|> value
+ (:coerce RubyString)
+ (RubyString::encode ["UTF-8"])
+ (RubyString::bytes []))}))
(def: (utf8\decode value)
(-> Binary (Try Text))
@@ -252,10 +267,18 @@
#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")))
+
+ @.lua
+ (#try.Success ("lua utf8 decode" value))
- ## Default
- (#try.Success ("lua utf8 decode" value)))))
+ @.ruby
+ (|> value
+ (:coerce RubyArray)
+ (RubyArray::pack ["C*"])
+ (:coerce RubyString)
+ (RubyString::force_encoding ["UTF-8"])
+ #try.Success)})))
(structure: #export utf8
(Codec Binary Text)