MCPcopy Index your code
hub / github.com/segmentio/encoding / parseUint

Method parseUint

json/parse.go:163–201  ·  view source on GitHub ↗

parseUint is like parseInt but for unsigned integers.

(b []byte, t reflect.Type)

Source from the content-addressed store, hash-verified

161
162// parseUint is like parseInt but for unsigned integers.
163func (d decoder) parseUint(b []byte, t reflect.Type) (uint64, []byte, error) {
164 var value uint64
165 var count int
166
167 if len(b) == 0 {
168 return 0, b, syntaxError(b, "cannot decode integer value from an empty input")
169 }
170
171 if len(b) > 1 && b[0] == '0' && '0' <= b[1] && b[1] <= '9' {
172 return 0, b, syntaxError(b, "invalid leading character '0' in integer")
173 }
174
175 for ; count < len(b) && b[count] >= '0' && b[count] <= '9'; count++ {
176 x := uint64(b[count] - '0')
177 next := value*10 + x
178 if next < value {
179 return 0, b, unmarshalOverflow(b, t)
180 }
181 value = next
182 }
183
184 if count == 0 {
185 b, err := d.inputError(b, t)
186 return 0, b, err
187 }
188
189 if count < len(b) {
190 switch b[count] {
191 case '.', 'e', 'E': // was this actually a float?
192 v, r, _, err := d.parseNumber(b)
193 if err != nil {
194 v, r = b[:count+1], b[count+1:]
195 }
196 return 0, r, unmarshalTypeError(v, t)
197 }
198 }
199
200 return value, b[count:], nil
201}
202
203// parseUintHex parses a hexadecimanl representation of a uint64 from b.
204//

Callers 7

decodeUintMethod · 0.95
decodeUintptrMethod · 0.95
decodeUint8Method · 0.95
decodeUint16Method · 0.95
decodeUint32Method · 0.95
decodeUint64Method · 0.95
UintMethod · 0.80

Calls 5

inputErrorMethod · 0.95
parseNumberMethod · 0.95
syntaxErrorFunction · 0.85
unmarshalOverflowFunction · 0.85
unmarshalTypeErrorFunction · 0.85

Tested by

no test coverage detected