-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
decode.go
63 lines (50 loc) · 1.23 KB
/
decode.go
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
package httpsfv
import (
"errors"
"fmt"
)
// ErrUnexpectedEndOfString is returned when the end of string is unexpected.
var ErrUnexpectedEndOfString = errors.New("unexpected end of string")
// ErrUnrecognizedCharacter is returned when an unrecognized character in encountered.
var ErrUnrecognizedCharacter = errors.New("unrecognized character")
// UnmarshalError contains the underlying parsing error and the position at which it occurred.
type UnmarshalError struct {
off int
err error
}
func (e *UnmarshalError) Error() string {
if e.err != nil {
return fmt.Sprintf("%s: character %d", e.err, e.off)
}
return fmt.Sprintf("unmarshal error: character %d", e.off)
}
func (e *UnmarshalError) Unwrap() error {
return e.err
}
type scanner struct {
data string
off int
}
// scanWhileSp consumes spaces.
func (s *scanner) scanWhileSp() {
for !s.eof() {
if s.data[s.off] != ' ' {
return
}
s.off++
}
}
// scanWhileOWS consumes optional white space (OWS) characters.
func (s *scanner) scanWhileOWS() {
for !s.eof() {
c := s.data[s.off]
if c != ' ' && c != '\t' {
return
}
s.off++
}
}
// eof returns true if the parser consumed all available characters.
func (s *scanner) eof() bool {
return s.off == len(s.data)
}