Skip to content

Instantly share code, notes, and snippets.

@Stmol
Created June 14, 2024 11:36
Show Gist options
  • Save Stmol/e48175a1b12b3a2a7ce8354a0a928d05 to your computer and use it in GitHub Desktop.
Save Stmol/e48175a1b12b3a2a7ce8354a0a928d05 to your computer and use it in GitHub Desktop.
test
type ValueType = number
const InvalidValue: ValueType = 1 << 0,
StringValue: ValueType = 1 << 1,
NumberValue: ValueType = 1 << 2,
NilValue: ValueType = 1 << 3,
BoolValue: ValueType = 1 << 4,
ArrayValue: ValueType = 1 << 5,
ObjectValue: ValueType = 1 << 6
let hexDigits: Uint8Array
let valueTypes: ValueType[]
function init() {
hexDigits = new Uint8Array(256)
hexDigits.fill(255)
// blah blah
// ....
}
type Iterator = {
buf: Uint8Array
head: number
tail: number
depth: number
captureStartedAt?: number
captured?: number
Error?: Error
Attachment?: any
}
export function NewIterator(cfg: any): Iterator {
return {
buf: new Uint8Array(),
head: 0,
tail: 0,
depth: 0,
}
}
function skipWhitespacesWithoutLoadMore(iter: Iterator): boolean {
for (let i = iter.head; i < iter.tail; i++) {
let c = String(iter.buf[i])
switch (c) {
case ' ':
case '\n':
case '\t':
case '\r':
continue
}
iter.head = i
return false
}
return true
}
export function ReportError(iter: Iterator, operation: string, msg: string): void {
if (iter.Error !== undefined) {
if (iter.Error instanceof Error) { // io.EOF type
return
}
}
let peekStart = iter.head - 10
if (peekStart < 0) {
peekStart = 0
}
// blah blah
iter.Error = new Error(
`${operation}: ${operation} error found in ${msg} byte of ...|${iter.head}|...`
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment