encoding.bend relies on unsafe/foreign
raw source on the hub · import 0xcf34b194ae12d241582d6ab00bc424e2/encoding.bend as Encoding
Hex of each char as two nibbles.
1 import
import Base
Types
type Utf8 source · line 128 · raw
Data
Decoder state: continuation bytes still needed, the allowed range of the next one, the code point so far, and the output reversed.
Utf8@need:U32 -> @lo:U32 -> @hi:U32 -> @cp:U32 -> @out:String -> Utf8
Definitions
def nibble source · line 6 · raw
@+n:U32 -> U32
def hi source · line 17 · raw
@+n:U32 -> U32
def lo source · line 20 · raw
@+n:U32 -> U32
def encode.go source · line 23 · raw
@s:String -> @acc:String -> String
def encode source · line 30 · raw
@s:String -> String
def unhex.h source · line 33 · raw
@c:U32 -> @hex:Bool -> Maybe<&2, U32>
def unhex.d source · line 40 · raw
@+c:U32 -> @dec:Bool -> @hex:Bool -> Maybe<&2, U32>
def unhex source · line 47 · raw
@+c:U32 -> Maybe<&2, U32>
def decode.cons source · line 50 · raw
@byte:U32 -> @rest:Maybe<&2, String> -> Maybe<&2, String>
def decode.join2 source · line 57 · raw
@x:U32 -> @b:Maybe<&2, U32> -> @rest:Maybe<&2, String> -> Maybe<&2, String>
def decode.join source · line 64 · raw
@a:Maybe<&2, U32> -> @b:Maybe<&2, U32> -> @rest:Maybe<&2, String> -> Maybe<&2, String>
def decode source · line 83 · raw
@s:String -> Maybe<&2, String>
def utf8.cont source · line 88 · raw
@c:U32 -> @n:Nat -> U32
def utf8.push4 source · line 91 · raw
@+c:U32 -> @acc:String -> String
def utf8.push3 source · line 94 · raw
@+c:U32 -> @acc:String -> @small:Bool -> String
def utf8.push2 source · line 101 · raw
@+c:U32 -> @acc:String -> @small:Bool -> String
def utf8.push source · line 108 · raw
@+c:U32 -> @acc:String -> @ascii:Bool -> String
def utf8.encode.go source · line 115 · raw
@s:String -> @acc:String -> String
def utf8.encode source · line 123 · raw
@s:String -> String
Text to octets.
def utf8.bad source · line 131 · raw
@out:String -> String
def utf8.lead.multi source · line 134 · raw
@+b:U32 -> @out:String -> Utf8
def utf8.lead.high source · line 140 · raw
@+b:U32 -> @out:String -> @bad:Bool -> Utf8
def utf8.lead source · line 148 · raw
@+b:U32 -> @out:String -> @ascii:Bool -> Utf8
WHATWG: a byte that cannot start a sequence decodes to U+FFFD.
def utf8.more source · line 155 · raw
@+need:U32 -> @cp:U32 -> @out:String -> @done:Bool -> Utf8
def utf8.cont.in source · line 163 · raw
@+need:U32 -> @cp:U32 -> @+b:U32 -> @out:String -> @ok:Bool -> Utf8
WHATWG: a byte that breaks a sequence yields U+FFFD and is read again as a lead.
def utf8.step.if source · line 170 · raw
@+need:U32 -> @+lo:U32 -> @+hi:U32 -> @cp:U32 -> @+b:U32 -> @out:String -> @idle:Bool -> Utf8
def utf8.step.st source · line 177 · raw
@st:Utf8 -> @+b:U32 -> Utf8
def utf8.finish source · line 181 · raw
@st:Utf8 -> String
def utf8.decode.go source · line 185 · raw
@s:String -> @st:Utf8 -> String
def utf8.decode source · line 193 · raw
@s:String -> String
Octets to text, as WHATWG decodes UTF-8: malformed input becomes U+FFFD.
Unsafe
unsafe hi.go source · line 10 · raw
@+n:U32 -> @+acc:U32 -> @small:Bool -> U32
unsafe decode.go source · line 72 · raw
@s:String -> Maybe<&2, String>