diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-03-31 16:35:25 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2016-03-31 16:35:25 +0200 |
commit | b296e7c01f3d29e2e429bfc1fc4203727cd3b1ce (patch) | |
tree | 5debdaf0b92934af508d9ef2568c654682f6fb64 /lib/pure/strutils.nim | |
parent | d836028fe7b18c93c9a9751f470da387eab09af1 (diff) | |
parent | c34a68d76f7f552b235592da7634acc333275df9 (diff) | |
download | Nim-b296e7c01f3d29e2e429bfc1fc4203727cd3b1ce.tar.gz |
Merge pull request #4013 from vegansk/parse_uints
parseUInt and parseBiggestUInt functions
Diffstat (limited to 'lib/pure/strutils.nim')
-rw-r--r-- | lib/pure/strutils.nim | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index f2c1e77e1..eebadf4c0 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -560,6 +560,24 @@ proc parseBiggestInt*(s: string): BiggestInt {.noSideEffect, procvar, if L != s.len or L == 0: raise newException(ValueError, "invalid integer: " & s) +proc parseUInt*(s: string): uint {.noSideEffect, procvar, + rtl, extern: "nsuParseUInt".} = + ## Parses a decimal unsigned integer value contained in `s`. + ## + ## If `s` is not a valid integer, `ValueError` is raised. + var L = parseutils.parseUInt(s, result, 0) + if L != s.len or L == 0: + raise newException(ValueError, "invalid unsigned integer: " & s) + +proc parseBiggestUInt*(s: string): uint64 {.noSideEffect, procvar, + rtl, extern: "nsuParseBiggestUInt".} = + ## Parses a decimal unsigned integer value contained in `s`. + ## + ## If `s` is not a valid integer, `ValueError` is raised. + var L = parseutils.parseBiggestUInt(s, result, 0) + if L != s.len or L == 0: + raise newException(ValueError, "invalid unsigned integer: " & s) + proc parseFloat*(s: string): float {.noSideEffect, procvar, rtl, extern: "nsuParseFloat".} = ## Parses a decimal floating point value contained in `s`. If `s` is not |