summaryrefslogtreecommitdiff
path: root/scalar.go
diff options
context:
space:
mode:
authorDaniele Sluijters <[email protected]>2022-10-02 19:11:37 +0200
committerDaniele Sluijters <[email protected]>2022-10-02 19:11:37 +0200
commit08e5e4d9560ac248bb84e623eee4a25017c8637c (patch)
treeb1987bc95d347778704b4aff6d554a4f92c62638 /scalar.go
parentb3bcd8035e45ea06ee596f0c35144df847c365b6 (diff)
Support different integer formats
In Go you can format numbers in different ways, as doucment in https://go.dev/ref/spec#Integer_literals. ParseInt with a base of 0 will infer the correct base for the number based on a prefix 0x, 0b etc, and also supports the use of the _ to separate digits. This can be helpful with long numbers, to make things easier to read. This switches the ParseInt() calls to use a base of 0, ensuring that if ParseValue is called with an int like 100_000 it'll parse correctly instead of throw an error.
Diffstat (limited to 'scalar.go')
-rw-r--r--scalar.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/scalar.go b/scalar.go
index 421bfac..0c17cd4 100644
--- a/scalar.go
+++ b/scalar.go
@@ -108,13 +108,13 @@ func ParseValue(v reflect.Value, s string) error {
}
v.SetBool(x)
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- x, err := strconv.ParseInt(s, 10, v.Type().Bits())
+ x, err := strconv.ParseInt(s, 0, v.Type().Bits())
if err != nil {
return err
}
v.SetInt(x)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- x, err := strconv.ParseUint(s, 10, v.Type().Bits())
+ x, err := strconv.ParseUint(s, 0, v.Type().Bits())
if err != nil {
return err
}