summary refs log tree commit diff stats
path: root/lib/pure/strutils.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <andreas@andreas-desktop>2010-01-21 19:05:14 +0100
committerAndreas Rumpf <andreas@andreas-desktop>2010-01-21 19:05:14 +0100
commit0ea4b71eec1fc2b738b203e4196f281be49d6aae (patch)
treee301abea641bd18e57db05cd98829ba196e97ca5 /lib/pure/strutils.nim
parentb50133b50f12025faf4801558f7e42cd96493da0 (diff)
downloadNim-0ea4b71eec1fc2b738b203e4196f281be49d6aae.tar.gz
atomic is now a keyword
Diffstat (limited to 'lib/pure/strutils.nim')
-rwxr-xr-xlib/pure/strutils.nim16
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)
/a>
f07bb12f ^









34a60763 ^
f07bb12f ^











































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89