def scan_hex

qasim-bend-kit@0.1.0.2 · libs/JSON.bend:350

import qasim-bend-kit@0.1.0.2/libs/JSON.bend as JSON
import Base

350def scan_hex(n: Nat, s: String, acc: U32) -> Result<&1, &1, Error, HexScan>:
351    match n:
352        case 0n:
353            Done{HexScan{acc, s}}
354        case 1n+p:
355            match s:
356                case SNil{}:
357                    Fail{Error{}}
358                case SCon{'0', t}:
359                    scan_hex(p, t, (acc * 16 + 0 : U32))
360                case SCon{'1', t}:
361                    scan_hex(p, t, (acc * 16 + 1 : U32))
362                case SCon{'2', t}:
363                    scan_hex(p, t, (acc * 16 + 2 : U32))
364                case SCon{'3', t}:
365                    scan_hex(p, t, (acc * 16 + 3 : U32))
366                case SCon{'4', t}:
367                    scan_hex(p, t, (acc * 16 + 4 : U32))
368                case SCon{'5', t}:
369                    scan_hex(p, t, (acc * 16 + 5 : U32))
370                case SCon{'6', t}:
371                    scan_hex(p, t, (acc * 16 + 6 : U32))
372                case SCon{'7', t}:
373                    scan_hex(p, t, (acc * 16 + 7 : U32))
374                case SCon{'8', t}:
375                    scan_hex(p, t, (acc * 16 + 8 : U32))
376                case SCon{'9', t}:
377                    scan_hex(p, t, (acc * 16 + 9 : U32))
378                case SCon{'a', t}:
379                    scan_hex(p, t, (acc * 16 + 10 : U32))
380                case SCon{'b', t}:
381                    scan_hex(p, t, (acc * 16 + 11 : U32))
382                case SCon{'c', t}:
383                    scan_hex(p, t, (acc * 16 + 12 : U32))
384                case SCon{'d', t}:
385                    scan_hex(p, t, (acc * 16 + 13 : U32))
386                case SCon{'e', t}:
387                    scan_hex(p, t, (acc * 16 + 14 : U32))
388                case SCon{'f', t}:
389                    scan_hex(p, t, (acc * 16 + 15 : U32))
390                case SCon{'A', t}:
391                    scan_hex(p, t, (acc * 16 + 10 : U32))
392                case SCon{'B', t}:
393                    scan_hex(p, t, (acc * 16 + 11 : U32))
394                case SCon{'C', t}:
395                    scan_hex(p, t, (acc * 16 + 12 : U32))
396                case SCon{'D', t}:
397                    scan_hex(p, t, (acc * 16 + 13 : U32))
398                case SCon{'E', t}:
399                    scan_hex(p, t, (acc * 16 + 14 : U32))
400                case SCon{'F', t}:
401                    scan_hex(p, t, (acc * 16 + 15 : U32))
402                case _:
403                    Fail{Error{}}

Uses (12)

Used by (1)