MCPcopy Create free account
hub / github.com/blues/note / Token

Method Token

jsonxt/stream.go:369–465  ·  view source on GitHub ↗

Token returns the next JSON token in the input stream. At the end of the input stream, Token returns nil, io.EOF. Token guarantees that the delimiters [ ] { } it returns are properly nested and matched: if Token encounters an unexpected delimiter in the input, it will return an error. The input st

()

Source from the content-addressed store, hash-verified

367// to mark the start and end of arrays and objects.
368// Commas and colons are elided.
369func (dec *Decoder) Token() (Token, error) {
370 for {
371 c, err := dec.peek()
372 if err != nil {
373 return nil, err
374 }
375 switch c {
376 case '[':
377 if !dec.tokenValueAllowed() {
378 return dec.tokenError(c)
379 }
380 dec.scanp++
381 dec.tokenStack = append(dec.tokenStack, dec.tokenState)
382 dec.tokenState = tokenArrayStart
383 return Delim('['), nil
384
385 case ']':
386 if dec.tokenState != tokenArrayStart && dec.tokenState != tokenArrayComma {
387 return dec.tokenError(c)
388 }
389 dec.scanp++
390 dec.tokenState = dec.tokenStack[len(dec.tokenStack)-1]
391 dec.tokenStack = dec.tokenStack[:len(dec.tokenStack)-1]
392 dec.tokenValueEnd()
393 return Delim(']'), nil
394
395 case '{':
396 if !dec.tokenValueAllowed() {
397 return dec.tokenError(c)
398 }
399 dec.scanp++
400 dec.tokenStack = append(dec.tokenStack, dec.tokenState)
401 dec.tokenState = tokenObjectStart
402 return Delim('{'), nil
403
404 case '}':
405 if dec.tokenState != tokenObjectStart && dec.tokenState != tokenObjectComma {
406 return dec.tokenError(c)
407 }
408 dec.scanp++
409 dec.tokenState = dec.tokenStack[len(dec.tokenStack)-1]
410 dec.tokenStack = dec.tokenStack[:len(dec.tokenStack)-1]
411 dec.tokenValueEnd()
412 return Delim('}'), nil
413
414 case ':':
415 if dec.tokenState != tokenObjectColon {
416 return dec.tokenError(c)
417 }
418 dec.scanp++
419 dec.tokenState = tokenObjectValue
420 // continue
421 return Delim(':'), nil
422
423 case ',':
424 if dec.tokenState == tokenArrayComma {
425 dec.scanp++
426 dec.tokenState = tokenArrayValue

Callers 2

BulkDecodeNextEntryMethod · 0.95
parseORIGTemplateFunction · 0.95

Calls 6

peekMethod · 0.95
tokenValueAllowedMethod · 0.95
tokenErrorMethod · 0.95
tokenValueEndMethod · 0.95
DecodeMethod · 0.95
DelimTypeAlias · 0.85

Tested by

no test coverage detected