Add the parser to parse the string as an integer if it's needed.
This commit is contained in:
@@ -3,7 +3,21 @@
|
||||
(:gen-class))
|
||||
|
||||
(defn unsigned-int?
|
||||
"Return true if the string is an unsigned integer."
|
||||
[str]
|
||||
(if (re-matches #"\d+" str)
|
||||
true false))
|
||||
|
||||
(defn parse-unsigned-int
|
||||
"Return an integer if the argument is an integer."
|
||||
[str-or-int]
|
||||
(cond
|
||||
(int? str-or-int)
|
||||
str-or-int
|
||||
|
||||
(unsigned-int? str-or-int)
|
||||
(Integer/parseInt str-or-int)
|
||||
|
||||
:else
|
||||
nil))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user