Files
cipher-analytical-machine/src/cipher_analytical_machine/parsers/parsers.clj
T
KKlochko e145382570
continuous-integration/drone/push Build is passing
Add int-string? to check if a string is a number.
2023-11-01 15:02:44 +02:00

30 lines
604 B
Clojure

(ns cipher-analytical-machine.parsers.parsers
(:require [cheshire.core :as cc])
(:gen-class))
(defn unsigned-int-string?
"Return true if the string is an unsigned integer."
[str]
(if (re-matches #"\d+" str)
true false))
(defn int-string?
"Return true if the string is an signed integer."
[str]
(if (re-matches #"[+-]?\b\d+\b" 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-string? str-or-int)
(Integer/parseInt str-or-int)
:else
nil))