MCPcopy Index your code
hub / github.com/dunglas/httpsfv / parseNumber

Function parseNumber

integer.go:39–92  ·  view source on GitHub ↗

parseNumber parses as defined in https://httpwg.org/specs/rfc9651.html#parse-number.

(s *scanner)

Source from the content-addressed store, hash-verified

37// parseNumber parses as defined in
38// https://httpwg.org/specs/rfc9651.html#parse-number.
39func parseNumber(s *scanner) (interface{}, error) {
40 neg := isNeg(s)
41 if neg && s.eof() {
42 return 0, &UnmarshalError{s.off, ErrUnexpectedEndOfString}
43 }
44
45 if !isDigit(s.data[s.off]) {
46 return 0, &UnmarshalError{s.off, ErrNotDigit}
47 }
48
49 start := s.off
50 s.off++
51
52 var (
53 decSepOff int
54 t = typeInteger
55 )
56
57 for s.off < len(s.data) {
58 size := s.off - start
59 if (t == typeInteger && (size >= 15)) || size >= 16 {
60 return 0, &UnmarshalError{s.off, ErrNumberOutOfRange}
61 }
62
63 c := s.data[s.off]
64 if isDigit(c) {
65 s.off++
66
67 continue
68 }
69
70 if t == typeInteger && c == '.' {
71 if size > maxDigit {
72 return 0, &UnmarshalError{s.off, ErrNumberOutOfRange}
73 }
74
75 t = typeDecimal
76 decSepOff = s.off
77 s.off++
78
79 continue
80 }
81
82 break
83 }
84
85 str := s.data[start:s.off]
86
87 if t == typeInteger {
88 return parseInteger(str, neg, s.off)
89 }
90
91 return parseDecimal(s, decSepOff, str, neg)
92}
93
94func isNeg(s *scanner) bool {
95 if s.data[s.off] == '-' {

Callers 3

parseDateFunction · 0.85
parseBareItemFunction · 0.85

Calls 5

isNegFunction · 0.85
isDigitFunction · 0.85
parseIntegerFunction · 0.85
parseDecimalFunction · 0.85
eofMethod · 0.80

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…