summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure')
-rwxr-xr-xlib/pure/math.nim4
-rwxr-xr-xlib/pure/strutils.nim16
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/pure/math.nim b/lib/pure/math.nim
index 50226f0f4..cf4b6d95c 100755
--- a/lib/pure/math.nim
+++ b/lib/pure/math.nim
@@ -1,12 +1,14 @@
 #
 #
 #            Nimrod's Runtime Library
-#        (c) Copyright 2009 Andreas Rumpf
+#        (c) Copyright 2010 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
 #
 
+##   Constructive mathematics is naturally typed. -- Simon Thompson
+## 
 ## Basic math routines for Nimrod.
 ## This module is available for the ECMAScript target.
 
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)