~/bend-docscommunity

encoding.bend relies on unsafe/foreign

raw source on the hub · import 0xcaf87330c1ce7eab5a1056378519aed8/encoding.bend as Encoding

1 import
import Base

Types

type Utf8 source · line 127 · raw

Data

Decoder state: continuation bytes still needed, the allowed range of the next one, the code point so far, and the output reversed.

Definitions

def nibble source · line 5 · raw

@+n:U32 -> U32

def hi source · line 16 · raw

@+n:U32 -> U32

def lo source · line 19 · raw

@+n:U32 -> U32

def encode.go source · line 22 · raw

@s:String -> @acc:String -> String

def encode source · line 29 · raw

@s:String -> String

def unhex.h source · line 32 · raw

@c:U32 -> @hex:Bool -> Maybe<&2, U32>

def unhex.d source · line 39 · raw

@+c:U32 -> @dec:Bool -> @hex:Bool -> Maybe<&2, U32>

def unhex source · line 46 · raw

@+c:U32 -> Maybe<&2, U32>

def decode.cons source · line 49 · raw

@byte:U32 -> @rest:Maybe<&2, String> -> Maybe<&2, String>

def decode.join2 source · line 56 · raw

@x:U32 -> @b:Maybe<&2, U32> -> @rest:Maybe<&2, String> -> Maybe<&2, String>

def decode.join source · line 63 · raw

@a:Maybe<&2, U32> -> @b:Maybe<&2, U32> -> @rest:Maybe<&2, String> -> Maybe<&2, String>

def decode source · line 82 · raw

@s:String -> Maybe<&2, String>

def utf8.cont source · line 87 · raw

@c:U32 -> @n:Nat -> U32

def utf8.push4 source · line 90 · raw

@+c:U32 -> @acc:String -> String

def utf8.push3 source · line 93 · raw

@+c:U32 -> @acc:String -> @small:Bool -> String

def utf8.push2 source · line 100 · raw

@+c:U32 -> @acc:String -> @small:Bool -> String

def utf8.push source · line 107 · raw

@+c:U32 -> @acc:String -> @ascii:Bool -> String

def utf8.encode.go source · line 114 · raw

@s:String -> @acc:String -> String

def utf8.encode source · line 122 · raw

@s:String -> String

Text to octets.

def utf8.bad source · line 130 · raw

@out:String -> String

def utf8.lead.multi source · line 133 · raw

@+b:U32 -> @out:String -> Utf8

def utf8.lead.high source · line 139 · raw

@+b:U32 -> @out:String -> @bad:Bool -> Utf8

def utf8.lead source · line 147 · 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 154 · raw

@+need:U32 -> @cp:U32 -> @out:String -> @done:Bool -> Utf8

def utf8.cont.in source · line 162 · 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 169 · raw

@+need:U32 -> @+lo:U32 -> @+hi:U32 -> @cp:U32 -> @+b:U32 -> @out:String -> @idle:Bool -> Utf8

def utf8.step.st source · line 176 · raw

@st:Utf8 -> @+b:U32 -> Utf8

def utf8.finish source · line 180 · raw

@st:Utf8 -> String

def utf8.decode.go source · line 184 · raw

@s:String -> @st:Utf8 -> String

def utf8.decode source · line 192 · raw

@s:String -> String

Octets to text, as WHATWG decodes UTF-8: malformed input becomes U+FFFD.

Unsafe

unsafe hi.go source · line 9 · raw

@+n:U32 -> @+acc:U32 -> @small:Bool -> U32

unsafe decode.go source · line 71 · raw

@s:String -> Maybe<&2, String>