BuildNumeric builds a Numeric type that represents any whole number. It normalizes the representation to ensure 1:1 mapping between the number and its representation.
(val string)
| 255 | // It normalizes the representation to ensure 1:1 mapping between the |
| 256 | // number and its representation. |
| 257 | func BuildNumeric(val string) (n Value, err error) { |
| 258 | if val[0] == '-' || val[0] == '+' { |
| 259 | signed, err := strconv.ParseInt(val, 0, 64) |
| 260 | if err != nil { |
| 261 | return Value{}, err |
| 262 | } |
| 263 | n = Value{Numeric(strconv.AppendInt(nil, signed, 10))} |
| 264 | } else { |
| 265 | unsigned, err := strconv.ParseUint(val, 0, 64) |
| 266 | if err != nil { |
| 267 | return Value{}, err |
| 268 | } |
| 269 | n = Value{Numeric(strconv.AppendUint(nil, unsigned, 10))} |
| 270 | } |
| 271 | return n, nil |
| 272 | } |
| 273 | |
| 274 | func (n Numeric) raw() []byte { |
| 275 | return []byte(n) |