Skip to content

Commit

Permalink
Fix string->num to only work in clj
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke committed Jul 18, 2024
1 parent 1d42bf7 commit 178a07e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/clj/game/core/servers.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
:archives -3
:rd -2
:hq -1
(string->num
(parse-long
(last (safe-split (str zone) #":remote")))))

(defn zones->sorted-names
Expand Down
9 changes: 5 additions & 4 deletions src/clj/game/utils.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@
(cons x (step more (conj seen k))))))))]
(step coll #{})))

(defn string->num [s]
(cond
(number? s) s
(string? s) (parse-long s)))
#?(:clj (defn string->num [s]
(try
(let [num (bigdec s)]
(if (and (> num Integer/MIN_VALUE) (< num Integer/MAX_VALUE)) (int num) num))
(catch Exception _ nil))))

(def safe-split (fnil str/split ""))

Expand Down

0 comments on commit 178a07e

Please sign in to comment.