~/bend-docscommunity

utf8.bend checks

raw source on the hub · import element-text@0.1.0.0/utf8.bend as Utf8

1 import
import Base

Definitions

def pick source · line 12 · raw

@c:Bool -> @a:U32 -> @b:U32 -> U32

def repl source · line 15 · raw

U32

def valid_cp source · line 19 · raw

@+c:U32 -> Bool

A code point Char.from_u32 accepts: not a surrogate, not past U+10FFFF.

def emit source · line 22 · raw

@+c:U32 -> @acc:List<&2, Char> -> List<&2, Char>

def emit_if source · line 25 · raw

@yes:Bool -> @+c:U32 -> @+acc:List<&2, Char> -> List<&2, Char>

def lead_need source · line 37 · raw

@+b:U32 -> U32

Continuation bytes a lead expects (0 for ASCII and for a byte that starts nothing).

def lead_bits source · line 43 · raw

@+b:U32 -> U32

def lead_lo source · line 49 · raw

@+b:U32 -> U32

The range the first continuation byte must fall in, after a lead.

def lead_hi source · line 52 · raw

@+b:U32 -> U32

def lead_bad source · line 57 · raw

@+b:U32 -> Bool

A byte that can start nothing: 80..C1 (a stray continuation or an overlong lead) and F5..FF.

def dec source · line 63 · raw

@bs:List<&2, U32> -> @+need:U32 -> @+cp:U32 -> @+lo:U32 -> @+hi:U32 -> @+acc:List<&2, Char> -> List<&2, Char>

One fold over the bytes. need continuation bytes are still expected for the code point cp built so far; the next one must be in lo..hi. Output is reversed.

def utf8 source · line 84 · raw

@bs:List<&2, U32> -> String

def latin1_go source · line 87 · raw

@bs:List<&2, U32> -> @acc:List<&2, Char> -> List<&2, Char>

def latin1 source · line 94 · raw

@bs:List<&2, U32> -> String

def ascii_prefix source · line 98 · raw

@n:Nat -> @bs:List<&2, U32> -> String

ASCII text of the first n bytes, for sniffing (bytes >= 128 become '?').

def after_key source · line 112 · raw

@s:String -> @+key:String -> String

The text after the first "charset=" in s, up to a delimiter. Empty if none.

def is_delim source · line 119 · raw

@+c:Char -> Bool

def token source · line 123 · raw

@s:String -> String

def strip_quote source · line 130 · raw

@+s:String -> String

def charset_in source · line 133 · raw

@+s:String -> String

def charset source · line 137 · raw

@+content_type:String -> @+bs:List<&2, U32> -> String

Header first, then <meta> in the first 1024 bytes, else utf-8.

def is_latin1 source · line 141 · raw

@+cs:String -> Bool

def decode source · line 147 · raw

@+content_type:String -> @+bs:List<&2, U32> -> String

windows-1252 differs from Latin-1 only in 0x80..0x9F; those bytes decode to C1 controls here (recorded gap, not silently "fixed").

def cp_bytes source · line 154 · raw

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

Strings hold Unicode scalar values, not octets. HTTP Content-Length and TLS plaintext must use the same UTF-8 encoding as TCP.send and WebSocket.

def bytes_of source · line 161 · raw

@s:String -> List<&2, U32>