def dec.go

bend-kit-tar@0.3.0.0 · tar.bend:86

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

86# Consume decimal digits and, when present, their first non-digit delimiter.
87def dec.go(n: Nat, r: Bytes.Cursor & Maybe<&2, DByte>, +acc: U32, +digits: U32, +ok: Bool) -> Bytes.Cursor & Dec:
88  match n:
89    case 0n:
90      (c, m) = r
91      (c, Dec{acc, digits, 0, True{}, ok})
92    case 1n+p:
93      (c, m) = r
94      match m:
95        case None{}:
96          (c, Dec{acc, digits, 0, True{}, False{}})
97        case Some{DByte{+b, digit}}:
98          match digit:
99            case False{}:
100              (c, Dec{acc, digits, b, False{}, ok})
101            case True{}:
102              +v = (b - 48 : U32)
103              +fit = U32.is_lt(acc, 429496729) || (U32.is_eq(acc, 429496729) && U32.is_le(v, 5))
104              dec.go(p, Bytes.Cursor.read(~DByte, ~dec.byte, c, 1), ((acc * 10) + v : U32), (digits + 1 : U32), ok && fit)

Uses (19)

Used by (1)