diff options
author | Andreas Rumpf <andreas@andreas-desktop> | 2010-01-21 19:05:14 +0100 |
---|---|---|
committer | Andreas Rumpf <andreas@andreas-desktop> | 2010-01-21 19:05:14 +0100 |
commit | 0ea4b71eec1fc2b738b203e4196f281be49d6aae (patch) | |
tree | e301abea641bd18e57db05cd98829ba196e97ca5 /lib/pure/strutils.nim | |
parent | b50133b50f12025faf4801558f7e42cd96493da0 (diff) | |
download | Nim-0ea4b71eec1fc2b738b203e4196f281be49d6aae.tar.gz |
atomic is now a keyword
Diffstat (limited to 'lib/pure/strutils.nim')
-rwxr-xr-x | lib/pure/strutils.nim | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 5cf1cf6a3..292810538 100755 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -328,7 +328,9 @@ proc ParseFloat*(s: string): float {.noSideEffect, procvar.} proc ParseHexInt*(s: string): int {.noSideEffect, procvar.} ## Parses a hexadecimal integer value contained in `s`. If `s` is not - ## a valid integer, `EInvalidValue` is raised. + ## a valid integer, `EInvalidValue` is raised. `s` can have one of the + ## following optional prefixes: ``0x``, ``0X``, ``#``. + ## Underscores within `s` are ignored. # the stringify and format operators: proc toString*[Ty](x: Ty): string {.deprecated.} @@ -735,10 +737,22 @@ proc ParseBiggestInt(s: string): biggestInt = if index == -1: raise newException(EInvalidValue, "invalid integer: " & s) +proc ParseOctInt*(s: string): int = + var i = 0 + if s[i] == '0' and (s[i+1] == 'o' or s[i+1] == 'O'): inc(i, 2) + while true: + case s[i] + of '_': inc(i) + of '0'..'7': + result = result shl 3 or (ord(s[i]) - ord('0')) + inc(i) + of '\0': break + else: raise newException(EInvalidValue, "invalid integer: " & s) proc ParseHexInt(s: string): int = var i = 0 if s[i] == '0' and (s[i+1] == 'x' or s[i+1] == 'X'): inc(i, 2) + elif s[i] == '#': inc(i) while true: case s[i] of '_': inc(i) |