Skip to content

Instantly share code, notes, and snippets.

(defn index-of-safe
"Return index of value (string or char) in s, optionally searching
forward from from-index. Return nil if value not found.
Works around https://bugs.openjdk.java.net/browse/JDK-8027640
so the returned index is always greater equal to from-index.
This also works around JavaScript's similar behavior."
[s value from-index]
(if (< (count s) from-index)
nil
(clojure.string/index-of s value from-index)))