Files
cipher-analytical-machine/src/cipher_analytical_machine/parsers/parsers.clj
T

24 lines
455 B
Clojure

(ns cipher-analytical-machine.parsers.parsers
(:require [cheshire.core :as cc])
(: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))