def parse.text.go

mylsm-lsm-store@0.6.0.1 · src/SstFile.bend:560

import mylsm-lsm-store@0.6.0.1/src/SstFile.bend as SstFile
import Base
import mylsm-lsm-store@0.6.0.1/src/StorageBytes.bend as StorageBytes
import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes

560# Read exactly n UTF-8 bytes from a bounded cursor without materializing a slice.
561def parse.text.go(
562  remaining: Nat,
563  read: TextRead,
564  state: StorageBytes.Utf8State
565) -> Bytes.Cursor & Result<&1, &1, Error, String>:
566  match remaining read:
567    case 0n DecodedText{cursor, _}:
568      parse.text.finish(cursor, StorageBytes.utf8.scan.fin(state))
569    case 1n+0n DecodedText{cursor, Some{+byte}}:
570      parse.text.finish(cursor, StorageBytes.utf8.scan.fin(
571        StorageBytes.utf8.step(state, byte)))
572    case 1n+1n+rest DecodedText{cursor, Some{+byte}}:
573      parse.text.go(1n+rest, parse.text.wrap(Bytes.Cursor.u8(cursor)),
574        StorageBytes.utf8.step(state, byte))
575    case 1n+_ DecodedText{cursor, None{}}:
576      (cursor, Fail{Malformed{}})

Uses (15)

Used by (1)