def uri.bytes

gralha-bytes@0.1.0.1 · bytes.bend:406

import gralha-bytes@0.1.0.1/bytes.bend as Bytes
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U

406def uri.bytes(+s: String, +out: Bytes) -> Bytes:
407  match s:
408    case SNil{}: out
409    case SCon{Chr{37}, SCon{Chr{a}, SCon{Chr{b}, rest}}}:
410      U.branch(Bytes, uri.hex.valid(a) && uri.hex.valid(b), _ => uri.bytes(rest, bytes.push(out, (U.hex.digit(a) * 16 + U.hex.digit(b) : U32))), _ => bytes.empty())
411    case SCon{Chr{c}, rest}:
412      U.branch(Bytes, U32.is_lt(c, 128) && Bool.not(U32.is_eq(c, 37)), _ => uri.bytes(rest, bytes.push(out, c)), _ => bytes.empty())
413
414@unsafe

Uses (18)

Used by (1)