about summary refs log tree commit diff stats
path: root/src/config
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-04-18 20:53:36 +0200
committerbptato <nincsnevem662@gmail.com>2024-04-18 21:12:50 +0200
commitc23ea622d1b34d3d290670e60e231f4f236fec50 (patch)
tree739abbf0490c28f5446469d7244a20a9a0a03502 /src/config
parent38db6ab5be80b255fe40df715adc3b5852875cdd (diff)
downloadchawan-c23ea622d1b34d3d290670e60e231f4f236fec50.tar.gz
url, twtstr: correct number parsing
* do not use std's parse*Int; they accept weird stuff that we do not
  want to accept in any case
* fix bug in parseHost where a parseIpv4 failure would result in an
  empty host
* do not use isDigit, isAlphaAscii
* improve parse*IntImpl error handling
Diffstat (limited to 'src/config')
-rw-r--r--src/config/toml.nim17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/config/toml.nim b/src/config/toml.nim
index f28c4916..f8ab9a08 100644
--- a/src/config/toml.nim
+++ b/src/config/toml.nim
@@ -1,6 +1,5 @@
 import std/options
 import std/streams
-import std/strutils
 import std/tables
 import std/times
 import std/unicode
@@ -441,21 +440,19 @@ proc consumeNumber(state: var TomlParser; c: char): TomlResult =
   case numType
   of NUMBER_INTEGER:
     let val = parseInt64(repr)
-    if not val.isSome:
+    if val.isNone:
       return state.err("invalid integer")
     return ok(TomlValue(t: tvtInteger, i: val.get))
   of NUMBER_HEX:
-    try:
-      let val = parseHexInt(repr)
-      return ok(TomlValue(t: tvtInteger, i: val))
-    except ValueError:
+    let val = parseHexInt64(repr)
+    if val.isNone:
       return state.err("invalid hexadecimal number")
+    return ok(TomlValue(t: tvtInteger, i: val.get))
   of NUMBER_OCT:
-    try:
-      let val = parseOctInt(repr)
-      return ok(TomlValue(t: tvtInteger, i: val))
-    except ValueError:
+    let val = parseOctInt64(repr)
+    if val.isNone:
       return state.err("invalid octal number")
+    return ok(TomlValue(t: tvtInteger, i: val.get))
   of NUMBER_FLOAT:
     let val = parseFloat64(repr)
     return ok(TomlValue(t: tvtFloat, f: val))