aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/text/encoding.lux
diff options
context:
space:
mode:
authorEduardo Julian2018-07-05 02:07:59 -0400
committerEduardo Julian2018-07-05 02:07:59 -0400
commit1b5cb7ab5ff0b774f0cd12f9504b82dae9ae977d (patch)
tree49c957a086c19c37967d9d10c026e87dac495272 /stdlib/source/lux/data/text/encoding.lux
parentb8e44ec6ee38d3f67b7e3c3989de51b03e7a1352 (diff)
- Binary (de)serialization module.
Diffstat (limited to 'stdlib/source/lux/data/text/encoding.lux')
-rw-r--r--stdlib/source/lux/data/text/encoding.lux23
1 files changed, 23 insertions, 0 deletions
diff --git a/stdlib/source/lux/data/text/encoding.lux b/stdlib/source/lux/data/text/encoding.lux
new file mode 100644
index 000000000..eb3b618c4
--- /dev/null
+++ b/stdlib/source/lux/data/text/encoding.lux
@@ -0,0 +1,23 @@
+(.module:
+ lux
+ (lux (data [error #+ Error])
+ (world [blob #+ Blob])
+ (lang ["_" host])
+ [host #+ import:]))
+
+(`` (for {(~~ (static _.jvm))
+ (as-is (def: utf8 Text "UTF-8")
+
+ (import: java/lang/String
+ (new [(Array byte) String])
+ (getBytes [String] (Array byte))))}))
+
+(def: #export (to-utf8 value)
+ (-> Text Blob)
+ (`` (for {(~~ (static _.jvm))
+ (String::getBytes [..utf8] value)})))
+
+(def: #export (from-utf8 value)
+ (-> Blob (Error Text))
+ (`` (for {(~~ (static _.jvm))
+ (#error.Success (String::new [value ..utf8]))})))