fix scanner error of number like "100f"

This commit is contained in:
Tnze
2021-05-27 14:58:40 +08:00
parent 82a2efd6a0
commit 69a8bad025
2 changed files with 20 additions and 51 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,6 @@ package nbt
import (
"errors"
"sync"
)
const (
@ -47,28 +46,6 @@ func (s *scanner) reset() {
s.parseState = s.parseState[0:0]
}
var scannerPool = sync.Pool{
New: func() interface{} {
return &scanner{}
},
}
func newScanner() *scanner {
scan := scannerPool.Get().(*scanner)
// scan.reset by design doesn't set bytes to zero
//scan.bytes = 0
scan.reset()
return scan
}
func freeScanner(scan *scanner) {
// Avoid hanging on to too much memory in extreme cases.
if len(scan.parseState) > 1024 {
scan.parseState = nil
}
scannerPool.Put(scan)
}
// pushParseState pushes a new parse state p onto the parse stack.
// an error state is returned if maxNestingDepth was exceeded, otherwise successState is returned.
func (s *scanner) pushParseState(c byte, newParseState int, successState int) int {
@ -282,10 +259,6 @@ func (s *scanner) stateNum0(c byte) int {
s.step = s.stateNum1
return scanContinue
}
if isAllowedInUnquotedString(c) {
s.step = s.stateInUnquotedString
return scanContinue
}
return s.stateEndNumValue(c)
}
@ -298,10 +271,6 @@ func (s *scanner) stateNum1(c byte) int {
s.step = s.stateNumDot
return scanContinue
}
if isAllowedInUnquotedString(c) {
s.step = s.stateInUnquotedString
return scanContinue
}
return s.stateEndNumValue(c)
}
@ -326,10 +295,6 @@ func (s *scanner) stateNumDot0(c byte) int {
s.step = s.stateNumDot0
return scanContinue
}
if isAllowedInUnquotedString(c) {
s.step = s.stateInUnquotedString
return scanContinue
}
return s.stateEndNumDotValue(c)
}
@ -347,6 +312,10 @@ func (s *scanner) stateEndNumValue(c byte) int {
case 'f', 'F', 'd', 'D':
return s.stateEndNumDotValue(c)
}
if isAllowedInUnquotedString(c) {
s.step = s.stateInUnquotedString
return scanContinue
}
return s.stateEndValue(c)
}