1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
package json
import (
"bytes"
"encoding/json"
"io"
_ "unsafe"
"git.lukeshu.com/go/lowmemjson"
"git.lukeshu.com/go/lowmemjson/internal/jsonparse"
"git.lukeshu.com/go/lowmemjson/internal/jsonstring"
"git.lukeshu.com/go/lowmemjson/internal/jsonstruct"
)
var (
parseTag = jsonstruct.ParseTag
clearCache = jsonstruct.ClearCache
cachedTypeFields = jsonstruct.IndexStruct
)
type scanner = lowmemjson.ReEncoderConfig
func checkValid(in []byte, scan *lowmemjson.ReEncoderConfig) error {
return reencode(io.Discard, in, *scan)
}
func isValidNumber(s string) bool {
var parser jsonparse.Parser
for _, r := range s {
if t, _ := parser.HandleRune(r); !t.IsNumber() {
return false
}
}
if t, _ := parser.HandleEOF(); t == jsonparse.RuneTypeError {
return false
}
return true
}
const (
startDetectingCyclesAfter = 1000
)
func isSpace(c byte) bool {
switch c {
case 0x0020, 0x000A, 0x000D, 0x0009:
return true
default:
return false
}
}
type encodeState struct {
bytes.Buffer
}
func (es *encodeState) string(str string, _ bool) {
if err := jsonstring.EncodeStringFromString(&es.Buffer, lowmemjson.EscapeDefault, str); err != nil {
panic(err)
}
}
func (es *encodeState) stringBytes(str []byte, _ bool) {
if err := jsonstring.EncodeStringFromBytes(&es.Buffer, lowmemjson.EscapeDefault, str); err != nil {
panic(err)
}
}
type (
Token = json.Token
Delim = json.Delim
)
func (dec *Decoder) Token() (Token, error) {
panic("not implemented")
}
|