def Utf8.left
import bend-trace-context@0.2.0.0/trace_context.bend as TraceContextimport Base
2028# What is left of a budget after a text, or None once the text exceeds it.
2029# Measuring stops at the first character beyond the budget, and a None budget
2030# stays None.
2031def Utf8.left(text: String, budget: Maybe<&2, Nat>) -> Maybe<&2, Nat>:
2032 match text budget:
2033 case _ None{}:
2034 None{}
2035 case SNil{} Some{left}:
2036 Some{left}
2037 case SCon{char, tail} Some{left}:
2038 Utf8.left(tail, Budget.take(Utf8.width(char), left))