~/bend-docscommunity

src/unescape.bend checks

raw source on the hub · import ezhttp@0.23.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. What is guaranteed is under laws/, such as laws/UnescapeFindsReferences.bend.

2 imports
import Base
import ./entities.bend as Ents

Types

type Scan source · line 15 · 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)

Definitions

def fffd source · line 24 · raw

String

U+FFFD REPLACEMENT CHARACTER, alone

def cap source · line 31 · 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 35 · 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 49 · 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 53 · raw

@hex:Bool -> @+n:U32 -> @+d:U32 -> U32

a number with one more digit, held at cap() once past it

def w1252 source · line 58 · 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 64 · 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 75 · 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 84 · raw

@+n:U32 -> @drop:Bool -> String

a code point in range: nothing when Python drops it, else the character

def code.range source · line 92 · raw

@+n:U32 -> @bad:Bool -> String

a surrogate or a number past U+10FFFF is U+FFFD

def code.c1 source · line 100 · raw

@+n:U32 -> @c1:Bool -> String

0x80 to 0x9F as the table says

def code.cr source · line 109 · raw

@+n:U32 -> @cr:Bool -> String

0x0D is a carriage return

def code.zero source · line 117 · raw

@+n:U32 -> @zero:Bool -> String

0 is U+FFFD, else on to 0x0D

def code source · line 125 · raw

@+n:U32 -> String

what a numeric reference stands for: 0 is U+FFFD

def best.len source · line 131 · raw

@m:Maybe<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref> -> Nat

a name's length, or 0 for none yet

def best.take source · line 139 · raw

@best:Maybe<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref> -> @+r:0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref -> @longer:Bool -> Maybe<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref>

the better of the best so far and a name the text starts with: the longer

def best.hit source · line 148 · raw

@+best:Maybe<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref> -> @+r:0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref -> @+name:String -> @hit:Bool -> Maybe<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref>

a name the text starts with or not

def best.step source · line 157 · raw

@+best:Maybe<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref> -> @+r:0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref -> @+s:String -> Maybe<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref>

one table row against the best so far

def best source · line 164 · raw

@rs:List<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref> -> @+s:String -> @+sofar:Maybe<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref> -> Maybe<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/entities.Ref>

the longest name in the rows that the text starts with

def chars source · line 173 · raw

@first:U32 -> @+second:U32 -> String

the one or two characters a row stands for

def named.of source · line 179 · raw

@m:Maybe<&2, 0x7367809738fddd234b8d2bed772ad2cf/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 187 · raw

@+s:String -> String

a named reference's text (after the &, with its ; if it has one)

def name.char source · line 194 · raw

@+c:Char -> Bool

a character that may be in a name: anything but TAB, LF, FF, space, <, &, # and ;

def text.of source · line 201 · raw

@+c:Char -> @k:(@_:Scan -> String) -> @amp:Bool -> String

a character in text once it is known whether it is &

def text source · line 209 · raw

@+c:Char -> @k:(@_:Scan -> String) -> String

a character in text: & may open a reference

def amp.name source · line 213 · raw

@+c:Char -> @k:(@_:Scan -> String) -> @name:Bool -> String

after &: a name character opens a name, else the & is text

def amp source · line 221 · raw

@+c:Char -> @k:(@_:Scan -> String) -> @hash:Bool -> String

after &: # opens a number

def hash.x source · line 229 · raw

@+c:Char -> @k:(@_:Scan -> String) -> @x:Bool -> String

after &#: x or X opens a hexadecimal number

def hash.dec source · line 237 · 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 245 · raw

@+c:Char -> @k:(@_:Scan -> String) -> @+d:U32 -> String

after &#: a decimal digit opens a decimal number

def hash.hex.of source · line 249 · 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 258 · 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 263 · 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 271 · 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 280 · 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 285 · 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 294 · 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 303 · raw

@st:Scan -> @+c:Char -> @k:(@_:Scan -> String) -> String

one character where the scan stands

def end source · line 320 · 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 336 · raw

@s:String -> @st:Scan -> String

a text scanned from where it stands, character by character

def unescape source · line 344 · raw

@s:String -> String

a text with its character references replaced, as html.unescape