Target.utf.lead: def of bend-kit-router@0.2.0.0 Import: import bend-kit-router@0.2.0.0/target.bend as Target Lines 16-26 of bend-kit-router@0.2.0.0/target.bend: https://jend.leeeet.dev/read.txt?path=bend-kit-router@0.2.0.0/target.bend&start_line=16&end_line=26 import Base def utf.lead(+c: U32, out: String, ascii: Bool) -> Maybe<&2, Utf>: match ascii: case True{}: Some{Utf{0, 128, 191, 0, SCon{Chr{c}, out}}} case False{}: +valid = between(c, 194, 244) +need = Bool.pick(U32, U32.is_lt(c, 224), 1, Bool.pick(U32, U32.is_lt(c, 240), 2, 3)) +lo = Bool.pick(U32, U32.is_eq(c, 224), 160, Bool.pick(U32, U32.is_eq(c, 240), 144, 128)) +hi = Bool.pick(U32, U32.is_eq(c, 237), 159, Bool.pick(U32, U32.is_eq(c, 244), 143, 191)) mask = Bool.pick(U32, U32.is_eq(need, 1), 31, Bool.pick(U32, U32.is_eq(need, 2), 15, 7)) Bool.pick(Maybe<&2, Utf>, valid, Some{Utf{need, lo, hi, (c .&. mask : U32), out}}, None{}) Uses (11): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.pick https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Char https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Maybe https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.and https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_eq https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_lt https://jend.leeeet.dev/definition.txt?path=bend-kit-router@0.2.0.0/target.bend&name=Utf https://jend.leeeet.dev/definition.txt?path=bend-kit-router@0.2.0.0/target.bend&name=between