src/unescape.bend checks
raw source on the hub · import emerging-ezhttp@0.19.0.0/src/unescape.bend as Unescape
ezhttp/src/unescape: HTML character references back to the characters they
stand for, the way Python's html.unescape does it (the HTML Standard's
§13.2.5.72 to §13.2.5.80 character reference states, with Python's choices
where the parser would report an error). Numeric references are decimal
(&) or hexadecimal (&); named ones come from the HTML
Standard's table (src/entities.bend), the legacy names also without their
;. Pure. SPEC.md HTTP-REF lists what is guaranteed.
2 imports
import Base import ./entities.bend as Ents
Types
type Scan source · line 14 · raw
Data
where the scan stands: in text, after &, after &#, after &#x (the x
or X kept), inside a number (hexadecimal or not, its value so far), or
inside a name (its text so far and how many characters it has)
TxtScan
AmpScan
HashScan
HashX@x:Char -> Scan
Num@hex:Bool -> @n:U32 -> Scan
Name@text:String -> @len:Nat -> Scan
Definitions
def fffd source · line 23 · raw
String
U+FFFD REPLACEMENT CHARACTER, alone
def cap source · line 30 · raw
U32
the value a number is held at once it is past U+10FFFF: any larger one reads the same (U+FFFD)
def digit.of source · line 34 · raw
@hex:Bool -> @+cp:U32 -> U32
a digit's value in a base (16 or 10), or 16 when it is not one
def digit source · line 48 · raw
@hex:Bool -> @c:Char -> U32
a character's value as a digit in a base, or 16 when it is not one
def grow source · line 52 · raw
@hex:Bool -> @+n:U32 -> @+d:U32 -> U32
a number with one more digit, held at cap() once past it
def w1252 source · line 57 · raw
List<&2, U32>
what 0x80 to 0x9F stand for (HTML §13.2.5.80's table: Windows-1252, the five it leaves undefined as themselves)
def nth source · line 63 · raw
@xs:List<&2, U32> -> @i:Nat -> U32
the code point at a place in a list, 65533 past its end
def dropped source · line 74 · raw
@+n:U32 -> Bool
a code point Python drops: C0 controls but TAB, LF, FF and CR, DEL and the C1 controls, and the noncharacters U+FDD0 to U+FDEF and U+xFFFE, U+xFFFF
def code.kept source · line 83 · raw
@+n:U32 -> @drop:Bool -> String
a code point in range: nothing when Python drops it, else the character
def code.range source · line 91 · raw
@+n:U32 -> @bad:Bool -> String
a surrogate or a number past U+10FFFF is U+FFFD
def code.c1 source · line 99 · raw
@+n:U32 -> @c1:Bool -> String
0x80 to 0x9F as the table says
def code.cr source · line 108 · raw
@+n:U32 -> @cr:Bool -> String
0x0D is a carriage return
def code.zero source · line 116 · raw
@+n:U32 -> @zero:Bool -> String
0 is U+FFFD, else on to 0x0D
def code source · line 124 · raw
@+n:U32 -> String
what a numeric reference stands for: 0 is U+FFFD
def best.len source · line 130 · raw
@m:Maybe<&2, 0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref> -> Nat
a name's length, or 0 for none yet
def best.take source · line 138 · raw
@best:Maybe<&2, 0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref> -> @+r:0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref -> @longer:Bool -> Maybe<&2, 0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref>
the better of the best so far and a name the text starts with: the longer
def best.hit source · line 147 · raw
@+best:Maybe<&2, 0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref> -> @+r:0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref -> @+name:String -> @hit:Bool -> Maybe<&2, 0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref>
a name the text starts with or not
def best.step source · line 156 · raw
@+best:Maybe<&2, 0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref> -> @+r:0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref -> @+s:String -> Maybe<&2, 0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref>
one table row against the best so far
def best source · line 163 · raw
@rs:List<&2, 0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref> -> @+s:String -> @+sofar:Maybe<&2, 0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref> -> Maybe<&2, 0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref>
the longest name in the rows that the text starts with
def chars source · line 172 · raw
@first:U32 -> @+second:U32 -> String
the one or two characters a row stands for
def named.of source · line 178 · raw
@m:Maybe<&2, 0x60f672946f1b37cf58e2c05154bec295/src/entities.Ref> -> @s:String -> String
a reference's text once its longest name is known: the characters, then
the text after the name as written; with no name, & and the text
def named source · line 186 · raw
@+s:String -> String
a named reference's text (after the &, with its ; if it has one)
def name.char source · line 193 · raw
@+c:Char -> Bool
a character that may be in a name: anything but TAB, LF, FF, space, <,
&, # and ;
def text.of source · line 200 · raw
@+c:Char -> @k:(@_:Scan -> String) -> @amp:Bool -> String
a character in text once it is known whether it is &
def text source · line 208 · raw
@+c:Char -> @k:(@_:Scan -> String) -> String
a character in text: & may open a reference
def amp.name source · line 212 · raw
@+c:Char -> @k:(@_:Scan -> String) -> @name:Bool -> String
after &: a name character opens a name, else the & is text
def amp source · line 220 · raw
@+c:Char -> @k:(@_:Scan -> String) -> @hash:Bool -> String
after &: # opens a number
def hash.x source · line 228 · raw
@+c:Char -> @k:(@_:Scan -> String) -> @x:Bool -> String
after &#: x or X opens a hexadecimal number
def hash.dec source · line 236 · raw
@+c:Char -> @k:(@_:Scan -> String) -> @+d:U32 -> @digit:Bool -> String
after &#, once it is known whether the character is a decimal digit
def hash source · line 244 · raw
@+c:Char -> @k:(@_:Scan -> String) -> @+d:U32 -> String
after &#: a decimal digit opens a decimal number
def hash.hex.of source · line 248 · raw
@+x:Char -> @+c:Char -> @k:(@_:Scan -> String) -> @+d:U32 -> @digit:Bool -> String
after &#x, once it is known whether the character is a hex digit
def hash.hex source · line 257 · raw
@+x:Char -> @+c:Char -> @k:(@_:Scan -> String) -> @+d:U32 -> String
after &#x: a hex digit opens the number, else &#x is text
def num.end source · line 262 · raw
@+n:U32 -> @+c:Char -> @k:(@_:Scan -> String) -> @semi:Bool -> String
inside a number, a character that is not a digit: ; ends the reference
with it, anything else ends it and is text
def num source · line 270 · raw
@+hex:Bool -> @+n:U32 -> @+c:Char -> @k:(@_:Scan -> String) -> @+d:U32 -> @digit:Bool -> String
inside a number: a digit grows it
def name.end source · line 279 · raw
@+s:String -> @+c:Char -> @k:(@_:Scan -> String) -> String
inside a name, a character that does not join it: the name ends there
def name.more source · line 284 · raw
@+s:String -> @len:Nat -> @+c:Char -> @k:(@_:Scan -> String) -> @join:Bool -> String
inside a name, a character that is not ;: a name character joins it
while it has fewer than 32
def name source · line 293 · raw
@+s:String -> @+len:Nat -> @+c:Char -> @k:(@_:Scan -> String) -> @semi:Bool -> String
inside a name: ; ends the reference with it
def step source · line 302 · raw
@st:Scan -> @+c:Char -> @k:(@_:Scan -> String) -> String
one character where the scan stands
def end source · line 319 · raw
@st:Scan -> String
the end of the text: a reference left open ends there, an &, &# or
&#x with nothing after it is text
def scan source · line 335 · raw
@s:String -> @st:Scan -> String
a text scanned from where it stands, character by character
def unescape source · line 343 · raw
@s:String -> String
a text with its character references replaced, as html.unescape