def utf8.need
import gralha-http-core@0.1.0.0/http.bend as Httpimport Base
81# Decoding reads a byte at a time: need is the continuation bytes still
82# owed and code the bits so far. A byte out of place is U+FFFD.
83def utf8.need(+b: U32, +need: U32) -> U32:
84 when(U32, U32.is_eq(need, 0),
85 _ => when(U32, U32.is_ge(b, 240), _ => 3, _ => when(U32, U32.is_ge(b, 224), _ => 2,
86 _ => when(U32, U32.is_ge(b, 192), _ => 1, _ => 0))),
87 _ => when(U32, U32.is_eq((b .&. 192 : U32), 128), _ => (need - 1 : U32), _ => 0))