MCPcopy Create free account
hub / github.com/segmentio/encoding / Next

Method Next

json/token.go:111–205  ·  view source on GitHub ↗

Next returns a new tokenizer pointing at the next token, or the zero-value of Tokenizer if the end of the json input has been reached. If the tokenizer encounters malformed json while reading the input the method sets t.Err to an error describing the issue, and returns false. Once an error has been

()

Source from the content-addressed store, hash-verified

109// has been encountered, the tokenizer will always fail until its input is
110// cleared by a call to its Reset method.
111func (t *Tokenizer) Next() bool {
112 if t.Err != nil {
113 return false
114 }
115
116 // Inlined code of the skipSpaces function, this give a ~15% speed boost.
117 i := 0
118skipLoop:
119 for _, c := range t.json {
120 switch c {
121 case sp, ht, nl, cr:
122 i++
123 default:
124 break skipLoop
125 }
126 }
127
128 if i > 0 {
129 t.json = t.json[i:]
130 }
131
132 if len(t.json) == 0 {
133 t.Reset(nil)
134 return false
135 }
136
137 var kind Kind
138 switch t.json[0] {
139 case '"':
140 t.Delim = 0
141 t.Value, t.json, kind, t.Err = t.parseString(t.json)
142 case 'n':
143 t.Delim = 0
144 t.Value, t.json, kind, t.Err = t.parseNull(t.json)
145 case 't':
146 t.Delim = 0
147 t.Value, t.json, kind, t.Err = t.parseTrue(t.json)
148 case 'f':
149 t.Delim = 0
150 t.Value, t.json, kind, t.Err = t.parseFalse(t.json)
151 case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
152 t.Delim = 0
153 t.Value, t.json, kind, t.Err = t.parseNumber(t.json)
154 case '{', '}', '[', ']', ':', ',':
155 t.Delim, t.Value, t.json = Delim(t.json[0]), t.json[:1], t.json[1:]
156 switch t.Delim {
157 case '{':
158 kind = Object
159 case '[':
160 kind = Array
161 }
162 default:
163 t.Delim = 0
164 t.Value, t.json, t.Err = t.json[:1], t.json[1:], syntaxError(t.json, "expected token but found '%c'", t.json[0])
165 }
166
167 t.Depth = t.depth()
168 t.Index = t.index()

Callers 15

tokenizeFunction · 0.95
BenchmarkTokenizerFunction · 0.95
encodeFuncMapOfFunction · 0.45
encodeFuncMapAsSetOfFunction · 0.45
BenchmarkCodeEncoderFunction · 0.45
BenchmarkCodeMarshalFunction · 0.45
BenchmarkCodeDecoderFunction · 0.45
BenchmarkCodeUnmarshalFunction · 0.45
BenchmarkUnmarshalStringFunction · 0.45

Calls 13

ResetMethod · 0.95
depthMethod · 0.95
indexMethod · 0.95
pushMethod · 0.95
popMethod · 0.95
syntaxErrorFunction · 0.85
parseStringMethod · 0.80
parseNullMethod · 0.80
parseTrueMethod · 0.80
parseFalseMethod · 0.80
parseNumberMethod · 0.80
withKindMethod · 0.80

Tested by 15

tokenizeFunction · 0.76
BenchmarkTokenizerFunction · 0.76
BenchmarkCodeEncoderFunction · 0.36
BenchmarkCodeMarshalFunction · 0.36
BenchmarkCodeDecoderFunction · 0.36
BenchmarkCodeUnmarshalFunction · 0.36
BenchmarkUnmarshalStringFunction · 0.36