aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/text/encoding.lux
diff options
context:
space:
mode:
authorEduardo Julian2021-03-01 01:49:30 -0400
committerEduardo Julian2021-03-01 01:49:30 -0400
commitcbc41f10fb3e0e776767d2266b22068172b0f69a (patch)
tree0344edcbe40edf51d16eb70b12a72e97e3c37f11 /stdlib/source/lux/data/text/encoding.lux
parent69edb6de2ecf62881bcde1b8013c98450a6a52bc (diff)
Done with Ruby.
Diffstat (limited to 'stdlib/source/lux/data/text/encoding.lux')
-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)