changed str-int to use try/catch instead of a regular expression check

This commit is contained in:
Richard Harrington
2013-07-16 12:04:10 -04:00
parent ae1c991310
commit 2cadd6a277
+4 -4
View File
@@ -46,10 +46,10 @@
:pos (:pos first-token)})
(defn str->int
"Like Integer/parseInt, but returns nil on failure"
[s]
(and (re-matches #"-?\d+" s)
(Integer/parseInt s)))
"Integer/parseInt, but returns nil on failure"
[s-raw]
(try (Integer/parseInt s-raw)
(catch Exception e nil)))
(defn valid-word
"Capital letters and numbers, starting with a capital letter"