def percent_codepoint_width

qasim-bend-kit@0.1.0.2 · libs/URL.bend:16

import qasim-bend-kit@0.1.0.2/libs/URL.bend as URL
import Base

16def percent_codepoint_width(+codepoint: U32, width: U32) -> String:
17    match width:
18        case 1: percent_byte(codepoint)
19        case 2: percent_byte((192 + U32.shrn(codepoint, 6n) : U32)) ++
20                percent_byte((128 + U32.and(codepoint, 63) : U32))
21        case 3: percent_byte((224 + U32.shrn(codepoint, 12n) : U32)) ++
22                percent_byte((128 + U32.and(U32.shrn(codepoint, 6n), 63) : U32)) ++
23                percent_byte((128 + U32.and(codepoint, 63) : U32))
24        case _: percent_byte((240 + U32.shrn(codepoint, 18n) : U32)) ++
25                percent_byte((128 + U32.and(U32.shrn(codepoint, 12n), 63) : U32)) ++
26                percent_byte((128 + U32.and(U32.shrn(codepoint, 6n), 63) : U32)) ++
27                percent_byte((128 + U32.and(codepoint, 63) : U32))

Uses (10)

Used by (1)