summaryrefslogtreecommitdiff
path: root/decode_scan.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-30 20:46:07 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-30 21:43:57 -0700
commit2e48a42fb9b9e946958810cfbb90ae85bee997e4 (patch)
treebc9bf437a34905f0b7249352043aff9e9d80ebe8 /decode_scan.go
parent7de3be7d772ab32adb1a865450ba60567367064c (diff)
decode: Remove unnecessary scanner struct members
Diffstat (limited to 'decode_scan.go')
-rw-r--r--decode_scan.go30
1 files changed, 12 insertions, 18 deletions
diff --git a/decode_scan.go b/decode_scan.go
index b9a5ea8..387fcea 100644
--- a/decode_scan.go
+++ b/decode_scan.go
@@ -35,28 +35,24 @@ type runeTypeScannerImpl struct {
inner io.RuneScanner // initialized by constructor
- initialized bool
-
parser internal.Parser // initialized by constructor
offset int64
- repeat bool
- stuck bool
- rRune rune
- rRuneOK bool
- rSize int
- rType internal.RuneType
- rErr error
+ initialized bool
+ repeat bool
+
+ rRune rune
+ rSize int
+ rType internal.RuneType
+ rErr error
}
var _ runeTypeScanner = (*runeTypeScannerImpl)(nil)
func (sc *runeTypeScannerImpl) Reset() {
sc.parser.Reset()
- unread := sc.stuck && sc.rType == internal.RuneTypeEOF && sc.rRuneOK
- sc.stuck = false
- sc.repeat = false
- if unread {
+ if sc.repeat || (sc.rType == internal.RuneTypeEOF && sc.rSize > 0) {
+ sc.repeat = false
// re-figure the rType and rErr
var err error
sc.rType, err = sc.parser.HandleRune(sc.rRune)
@@ -75,15 +71,15 @@ func (sc *runeTypeScannerImpl) Reset() {
func (sc *runeTypeScannerImpl) ReadRuneType() (rune, int, internal.RuneType, error) {
switch {
- case sc.stuck:
+ case sc.initialized && (sc.rType == internal.RuneTypeError || sc.rType == internal.RuneTypeEOF):
// do nothing
case sc.repeat:
_, _, _ = sc.inner.ReadRune()
default:
+ sc.initialized = true
var err error
sc.rRune, sc.rSize, err = sc.inner.ReadRune()
sc.offset += int64(sc.rSize)
- sc.rRuneOK = err == nil
switch err {
case nil:
sc.rType, err = sc.parser.HandleRune(sc.rRune)
@@ -113,9 +109,7 @@ func (sc *runeTypeScannerImpl) ReadRuneType() (rune, int, internal.RuneType, err
}
}
}
- sc.initialized = true
sc.repeat = false
- sc.stuck = sc.rType == internal.RuneTypeEOF || sc.rType == internal.RuneTypeError
return sc.rRune, sc.rSize, sc.rType, sc.rErr
}
@@ -137,7 +131,7 @@ func (sc *runeTypeScannerImpl) ReadRune() (rune, int, error) {
// unread, or if that call returned a rune with size 0, then
// ErrInvalidUnreadRune is returned. Otherwise, nil is returned.
func (sc *runeTypeScannerImpl) UnreadRune() error {
- if !sc.initialized || sc.repeat || sc.rSize == 0 {
+ if sc.repeat || sc.rSize == 0 {
return ErrInvalidUnreadRune
}
sc.repeat = true