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.lux155
1 files changed, 0 insertions, 155 deletions
diff --git a/stdlib/source/lux/data/text/encoding.lux b/stdlib/source/lux/data/text/encoding.lux
index 7445d5ebc..92f68dfe0 100644
--- a/stdlib/source/lux/data/text/encoding.lux
+++ b/stdlib/source/lux/data/text/encoding.lux
@@ -1,13 +1,5 @@
(.module:
[lux #*
- ["@" target]
- ["." ffi]
- [abstract
- [codec (#+ Codec)]]
- [control
- ["." try (#+ Try)]]
- [data
- ["." binary (#+ Binary)]]
[type
abstract]])
@@ -168,150 +160,3 @@
(-> Encoding Text)
(|>> :representation))
)
-
-(with_expansions [<jvm> (as_is (ffi.import: java/lang/String
- ["#::."
- (new [[byte] java/lang/String])
- (getBytes [java/lang/String] [byte])]))]
- (for {@.old (as_is <jvm>)
- @.jvm (as_is <jvm>)
-
- @.js
- (as_is (ffi.import: Uint8Array)
-
- ## On Node
- (ffi.import: Buffer
- (#static from #as from|encode [ffi.String ffi.String] Buffer)
- (#static from #as from|decode [Uint8Array] Buffer)
- (toString [ffi.String] ffi.String))
-
- ## On the browser
- (ffi.import: TextEncoder
- (new [ffi.String])
- (encode [ffi.String] Uint8Array))
-
- (ffi.import: TextDecoder
- (new [ffi.String])
- (decode [Uint8Array] ffi.String)))
-
- @.ruby
- (as_is (ffi.import: String #as RubyString
- (encode [Text] RubyString)
- (force_encoding [Text] Text)
- (bytes [] Binary))
-
- (ffi.import: Array #as RubyArray
- (pack [Text] RubyString)))
-
- @.php
- (as_is (ffi.import: Almost_Binary)
- (ffi.import: (unpack [ffi.String ffi.String] Almost_Binary))
- (ffi.import: (array_values [Almost_Binary] Binary))
- (def: php_byte_array_format "C*"))
-
- @.scheme
- ## https://srfi.schemers.org/srfi-140/srfi-140.html
- (as_is (ffi.import: (string->utf8 [Text] Binary))
- (ffi.import: (utf8->string [Binary] Text)))}
- (as_is)))
-
-(def: (utf8\encode value)
- (-> Text Binary)
- (for {@.old
- (java/lang/String::getBytes (..name ..utf_8)
- ## TODO: Remove coercion below.
- ## The coercion below may seem
- ## gratuitous, but removing it
- ## causes a grave compilation problem.
- (:coerce java/lang/String value))
-
- @.jvm
- (java/lang/String::getBytes (..name ..utf_8) value)
-
- @.js
- (cond ffi.on_nashorn?
- (:coerce Binary ("js object do" "getBytes" value ["utf8"]))
-
- ffi.on_node_js?
- (|> (Buffer::from|encode [value "utf8"])
- ## This coercion is valid as per NodeJS's documentation:
- ## https://nodejs.org/api/buffer.html#buffer_buffers_and_typedarrays
- (:coerce Uint8Array))
-
- ## On the browser
- (|> (TextEncoder::new [(..name ..utf_8)])
- (TextEncoder::encode [value]))
- )
-
- @.python
- (:coerce Binary ("python apply" (:assume ("python constant" "bytearray")) value "utf-8"))
-
- @.lua
- ("lua utf8 encode" value)
-
- @.ruby
- (|> value
- (:coerce RubyString)
- (RubyString::encode ["UTF-8"])
- (RubyString::bytes []))
-
- @.php
- (|> (..unpack [..php_byte_array_format value])
- ..array_values
- ("php object new" "ArrayObject")
- (:coerce Binary))
-
- @.scheme
- (..string->utf8 value)}))
-
-(def: (utf8\decode value)
- (-> Binary (Try Text))
- (with_expansions [<jvm> (#try.Success (java/lang/String::new value (..name ..utf_8)))]
- (for {@.old <jvm>
- @.jvm <jvm>
-
- @.js
- (cond ffi.on_nashorn?
- (|> ("js object new" ("js constant" "java.lang.String") [value "utf8"])
- (:coerce Text)
- #try.Success)
-
- ffi.on_node_js?
- (|> (Buffer::from|decode [value])
- (Buffer::toString ["utf8"])
- #try.Success)
-
- ## On the browser
- (|> (TextDecoder::new [(..name ..utf_8)])
- (TextDecoder::decode [value])
- #try.Success))
-
- @.python
- (ffi.try (:coerce Text ("python object do" "decode" (:assume value) "utf-8")))
-
- @.lua
- (#try.Success ("lua utf8 decode" value))
-
- @.ruby
- (|> value
- (:coerce RubyArray)
- (RubyArray::pack ["C*"])
- (:coerce RubyString)
- (RubyString::force_encoding ["UTF-8"])
- #try.Success)
-
- @.php
- (|> value
- ("php pack" ..php_byte_array_format)
- #try.Success)
-
- @.scheme
- (|> value
- ..utf8->string
- #try.Success)})))
-
-(structure: #export utf8
- (Codec Binary Text)
-
- (def: encode ..utf8\encode)
- (def: decode ..utf8\decode))