src/pct.bend checks
raw source on the hub · import ezhttp@0.24.0.0/src/pct.bend as Pct
ezhttp/src/pct: percent-encoding (RFC 3986 §2.1), the way Python's urllib.parse.quote does it. Unreserved characters (§2.3) are written as themselves; the path form also keeps "/"; every other character is written as the bytes of its UTF-8 encoding (RFC 3629 §3), each as "%" and two upper-case hex digits. What is guaranteed is under laws/, such as laws/QuoteKeepsUnreserved.bend.
1 import
import Base
Definitions
def unreserved source · line 10 · raw
@+cp:U32 -> Bool
RFC 3986 §2.3 unreserved: ALPHA / DIGIT / "-" / "." / "_" / "~"
def safe source · line 20 · raw
@slash:Bool -> @+cp:U32 -> Bool
a character a form writes as itself: unreserved, or "/" when slash (the
path form) keeps it
def hex source · line 24 · raw
@+nib:U32 -> Char
one hex digit, upper case: 0-9 then A-F ('A' is 55 + 10)
def pct source · line 28 · raw
@bytes:List<&2, U32> -> @rest:String -> String
bytes as %XX triples, high nibble first, followed by rest
def cont source · line 37 · raw
@+cp:U32 -> @shift:Nat -> U32
a continuation byte: 10xxxxxx from the six bits at shift
def utf8.four source · line 41 · raw
@+cp:U32 -> List<&2, U32>
four bytes: U+10000 to U+10FFFF
def utf8.three source · line 45 · raw
@+cp:U32 -> @fits:Bool -> List<&2, U32>
three bytes below U+10000, else four
def utf8.two source · line 53 · raw
@+cp:U32 -> @fits:Bool -> List<&2, U32>
two bytes below U+0800, else more
def utf8.one source · line 61 · raw
@+cp:U32 -> @fits:Bool -> List<&2, U32>
one byte below U+0080, else more
def utf8 source · line 69 · raw
@+cp:U32 -> List<&2, U32>
the UTF-8 bytes of one code point, in order (RFC 3629 §3)
def one.of source · line 73 · raw
@+cp:U32 -> @rest:String -> @kept:Bool -> String
one character, once it is known whether the form keeps it
def one source · line 81 · raw
@slash:Bool -> @+cp:U32 -> @rest:String -> String
one character as the form writes it, followed by rest
def quote source · line 85 · raw
@+slash:Bool -> @shift:String -> String
a string as the form writes it: each character in turn