parseUint is like parseInt but for unsigned integers.
(b []byte, t reflect.Type)
| 161 | |
| 162 | // parseUint is like parseInt but for unsigned integers. |
| 163 | func (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 | // |
no test coverage detected