def unb64.go

bend-kit-bytes@0.3.3.0 · bytes.bend:740

import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes
import Base

740# v collects six bits per char. '=' is allowed only at body and after.
741def unb64.go(s: String, a: Array<U32>, +i: U32, +v: U32, +ok: Bool, +len: U32, +body: U32) -> Array<U32> & Bool:
742  match s:
743    case SNil{}:
744      (a, ok)
745    case SCon{Chr{+c}, t}:
746      +d = b64.val(c)
747      +v2 = ((v << 6n) .|. (d .&. 63) : U32)
748      +o = ((i >> 2n) * 3 : U32)
749      +good = Bool.pick(Bool, U32.is_lt(i, body), U32.is_lt(d, 64), U32.is_eq(d, 64))
750      unb64.go(t, b64.put(U32.is_eq((i .&. 3 : U32), 3), a, o, U32.min(3, (len - o : U32)), v2), (i + 1 : U32), v2, Bool.and(ok, good), len, body)

Uses (21)

Used by (1)