aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/text/encoding.lux
blob: d5246e382cbba0952aa6879e599a1fc1b3f0e725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(.module:
  [lux #*
   [data
    ["." error (#+ Error)]]
   [world
    [blob (#+ Blob)]]
   [language
    ["_" 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]))})))