summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-02-19 21:01:04 +0100
committerAraq <rumpf_a@web.de>2012-02-19 21:01:04 +0100
commitccd58fba2cbc329eb42cd65c80d66ca09acad505 (patch)
tree8f0bd9aff5f3545dfe708fc65e683e543aecfb58 /lib/pure
parentb88d98c17a00171ddc1a9d8059ad713d174b800c (diff)
downloadNim-ccd58fba2cbc329eb42cd65c80d66ca09acad505.tar.gz
bugfix: semfold supports merging of '&'
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/matchers.nim15
-rwxr-xr-xlib/pure/parseutils.nim6
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/pure/matchers.nim b/lib/pure/matchers.nim
index f37d4397d..0495f2c30 100644
--- a/lib/pure/matchers.nim
+++ b/lib/pure/matchers.nim
@@ -44,8 +44,21 @@ proc validEmailAddress*(s: string): bool {.noSideEffect,
      "aero", "jobs", "museum": return true
   return false
 
+proc parseInt*(s: string, value: var int, validRange: TSlice[int]) {.
+  noSideEffect, rtl, extern: "nmatchParseInt".} =
+  ## parses `s` into an integer in the range `validRange`. If successful,
+  ## `value` is modified to contain the result. Otherwise no exception is
+  ## raised and `value` is not touched; this way a reasonable default value
+  ## won't be overwritten.
+  var x = value
+  try:
+    x = parseInt(s)
+  except EOverflow:
+    nil
+  if x in validRange: value = x
+
 when isMainModule:
-  assert "wuseldusel@codehome.com".validEmailAddress
+  doAssert "wuseldusel@codehome.com".validEmailAddress
   
 {.pop.}
 
diff --git a/lib/pure/parseutils.nim b/lib/pure/parseutils.nim
index f4dbcf7b8..fd9e880c6 100755
--- a/lib/pure/parseutils.nim
+++ b/lib/pure/parseutils.nim
@@ -196,7 +196,11 @@ proc parseBiggestInt*(s: string, number: var biggestInt, start = 0): int {.
   ## parses an integer starting at `start` and stores the value into `number`.
   ## Result is the number of processed chars or 0 if there is no integer.
   ## `EOverflow` is raised if an overflow occurs.
-  result = rawParseInt(s, number, start)
+  var res: biggestInt = number
+  # use 'res' for exception safety (don't write to 'number' in case of an
+  # overflow exception:
+  result = rawParseInt(s, res, start)
+  number = res
 
 proc parseInt*(s: string, number: var int, start = 0): int {.
   rtl, extern: "npuParseInt", noSideEffect.} =