def Utf8.width

bend-trace-context@0.2.0.0 · trace_context.bend:1997

import bend-trace-context@0.2.0.0/trace_context.bend as TraceContext
import Base

1997# The UTF-8 octets of a character. Bend characters are Unicode code points, so
1998# this is the size of the character's UTF-8 encoding: 1 to 4.
1999def Utf8.width(char: Char) -> Nat:
2000  match char:
2001    case Chr{+code}:
2002      Bool.pick(Nat, U32.is_lt(code, 128), 1n,
2003        Bool.pick(Nat, U32.is_lt(code, 2048), 2n,
2004          Bool.pick(Nat, U32.is_lt(code, 65536), 3n, 4n)))

Uses (4)

Used by (2)