diff options
author | Eduardo Julian | 2022-03-14 06:14:57 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-03-14 06:14:57 -0400 |
commit | 4965597043aca57a05760113f1851e96dad1eaf8 (patch) | |
tree | 8126d3e6394e38bc52918eea95a67546350bb95e /stdlib/source/library/lux/data/text/encoding | |
parent | cfd438517a46e025b15345e3570b02f5ea6165c0 (diff) |
Leaner syntax for the "for" macro.
Diffstat (limited to 'stdlib/source/library/lux/data/text/encoding')
-rw-r--r-- | stdlib/source/library/lux/data/text/encoding/utf8.lux | 256 |
1 files changed, 128 insertions, 128 deletions
diff --git a/stdlib/source/library/lux/data/text/encoding/utf8.lux b/stdlib/source/library/lux/data/text/encoding/utf8.lux index 915d6b895..9b13114a4 100644 --- a/stdlib/source/library/lux/data/text/encoding/utf8.lux +++ b/stdlib/source/library/lux/data/text/encoding/utf8.lux @@ -15,145 +15,145 @@ ["[1]::[0]" (new [[byte] java/lang/String]) (getBytes [java/lang/String] [byte])]))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) - @.js - (as_is (ffi.import: Uint8Array - "[1]::[0]") + @.js + (as_is (ffi.import: Uint8Array + "[1]::[0]") - ... On Node - (ffi.import: Buffer - "[1]::[0]" - ("static" from "as" from|encoded [ffi.String ffi.String] Buffer) - ("static" from "as" from|decoded [Uint8Array] Buffer) - (toString [ffi.String] ffi.String)) + ... On Node + (ffi.import: Buffer + "[1]::[0]" + ("static" from "as" from|encoded [ffi.String ffi.String] Buffer) + ("static" from "as" from|decoded [Uint8Array] Buffer) + (toString [ffi.String] ffi.String)) - ... On the browser - (ffi.import: TextEncoder - "[1]::[0]" - (new [ffi.String]) - (encode [ffi.String] Uint8Array)) - - (ffi.import: TextDecoder - "[1]::[0]" - (new [ffi.String]) - (decode [Uint8Array] ffi.String))) - - @.ruby - (as_is (ffi.import: String - "[1]::[0]" - (encode [Text] String) - (force_encoding [Text] Text) - (bytes [] Binary)) - - (ffi.import: Array - "[1]::[0]" - (pack [Text] String))) - - @.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)))] + ... On the browser + (ffi.import: TextEncoder + "[1]::[0]" + (new [ffi.String]) + (encode [ffi.String] Uint8Array)) + + (ffi.import: TextDecoder + "[1]::[0]" + (new [ffi.String]) + (decode [Uint8Array] ffi.String))) + + @.ruby + (as_is (ffi.import: String + "[1]::[0]" + (encode [Text] String) + (force_encoding [Text] Text) + (bytes [] Binary)) + + (ffi.import: Array + "[1]::[0]" + (pack [Text] String))) + + @.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: (encoded value) (-> Text Binary) - (for [@.old - (java/lang/String::getBytes (ffi.as_string (//.name //.utf_8)) - (ffi.as_string value)) - - @.jvm - (java/lang/String::getBytes (ffi.as_string (//.name //.utf_8)) - (ffi.as_string value)) - - @.js - (cond ffi.on_nashorn? - (:as Binary ("js object do" "getBytes" value ["utf8"])) - - ffi.on_node_js? - (|> (Buffer::from|encoded value "utf8") - ... This coercion is valid as per NodeJS's documentation: - ... https://nodejs.org/api/buffer.html#buffer_buffers_and_typedarrays - (:as Uint8Array)) - - ... On the browser - (|> (TextEncoder::new (//.name //.utf_8)) - (TextEncoder::encode [value])) - ) - - @.python - (:as Binary ("python apply" (:expected ("python constant" "bytearray")) [value "utf-8"])) - - @.lua - ("lua utf8 encode" value) - - @.ruby - (|> value - (:as String) - (String::encode "UTF-8") - (String::bytes)) - - @.php - (|> (..unpack [..php_byte_array_format value]) - ..array_values - ("php object new" "ArrayObject") - (:as Binary)) - - @.scheme - (..string->utf8 value)])) + (for @.old + (java/lang/String::getBytes (ffi.as_string (//.name //.utf_8)) + (ffi.as_string value)) + + @.jvm + (java/lang/String::getBytes (ffi.as_string (//.name //.utf_8)) + (ffi.as_string value)) + + @.js + (cond ffi.on_nashorn? + (:as Binary ("js object do" "getBytes" value ["utf8"])) + + ffi.on_node_js? + (|> (Buffer::from|encoded value "utf8") + ... This coercion is valid as per NodeJS's documentation: + ... https://nodejs.org/api/buffer.html#buffer_buffers_and_typedarrays + (:as Uint8Array)) + + ... On the browser + (|> (TextEncoder::new (//.name //.utf_8)) + (TextEncoder::encode [value])) + ) + + @.python + (:as Binary ("python apply" (:expected ("python constant" "bytearray")) [value "utf-8"])) + + @.lua + ("lua utf8 encode" value) + + @.ruby + (|> value + (:as String) + (String::encode "UTF-8") + (String::bytes)) + + @.php + (|> (..unpack [..php_byte_array_format value]) + ..array_values + ("php object new" "ArrayObject") + (:as Binary)) + + @.scheme + (..string->utf8 value))) (def: (decoded value) (-> Binary (Try Text)) (with_expansions [<jvm> {try.#Success (ffi.of_string (java/lang/String::new value (ffi.as_string (//.name //.utf_8))))}] - (for [@.old <jvm> - @.jvm <jvm> - - @.js - (cond ffi.on_nashorn? - (|> ("js object new" ("js constant" "java.lang.String") [value "utf8"]) - (:as Text) - {try.#Success}) - - ffi.on_node_js? - (|> (Buffer::from|decoded value) - (Buffer::toString "utf8") - {try.#Success}) - - ... On the browser - (|> (TextDecoder::new (//.name //.utf_8)) - (TextDecoder::decode value) - {try.#Success})) - - @.python - (try (:as Text ("python object do" "decode" (:expected value) ["utf-8"]))) - - @.lua - {try.#Success ("lua utf8 decode" value)} - - @.ruby - (|> value - (:as Array) - (Array::pack "C*") - (:as String) - (String::force_encoding "UTF-8") - {try.#Success}) - - @.php - (|> value - ("php pack" ..php_byte_array_format) - {try.#Success}) - - @.scheme - (|> value - ..utf8->string - {try.#Success})]))) + (for @.old <jvm> + @.jvm <jvm> + + @.js + (cond ffi.on_nashorn? + (|> ("js object new" ("js constant" "java.lang.String") [value "utf8"]) + (:as Text) + {try.#Success}) + + ffi.on_node_js? + (|> (Buffer::from|decoded value) + (Buffer::toString "utf8") + {try.#Success}) + + ... On the browser + (|> (TextDecoder::new (//.name //.utf_8)) + (TextDecoder::decode value) + {try.#Success})) + + @.python + (try (:as Text ("python object do" "decode" (:expected value) ["utf-8"]))) + + @.lua + {try.#Success ("lua utf8 decode" value)} + + @.ruby + (|> value + (:as Array) + (Array::pack "C*") + (:as String) + (String::force_encoding "UTF-8") + {try.#Success}) + + @.php + (|> value + ("php pack" ..php_byte_array_format) + {try.#Success}) + + @.scheme + (|> value + ..utf8->string + {try.#Success})))) (implementation: .public codec (Codec Binary Text) |