Add the parser to parse the string as an integer if it's needed.

This commit is contained in:
2023-10-23 15:51:30 +03:00
parent 553f4788e4
commit d357e82b54
2 changed files with 25 additions and 1 deletions
@@ -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))