Update java string methods to clojure functions

With Clojure 1.8.0 finally those string methods now have corresponding
Clojure functions.

Of note here is that the clojure.string/index-of function responds
with nil if nothing is found and not -1 as .IndexOf previously did.
This commit is contained in:
Damian Niemczyk 2016-01-25 21:30:57 +01:00 committed by Colin Jones
parent 52fe0cd615
commit a8fe71e26f
2 changed files with 5 additions and 5 deletions

View File

@ -24,7 +24,7 @@
"olleh" "olleh"
"hello" "hello"
13 13
-1 nil
"hello world" "hello world"
true true
false false

View File

@ -37,13 +37,13 @@
(= __ (string/reverse "hello")) (= __ (string/reverse "hello"))
"Maybe you want to find the index of the first occurence of a substring" "Maybe you want to find the index of the first occurence of a substring"
(= 0 (.indexOf "hello world" __)) (= 0 (string/index-of "hello world" __))
"Or maybe the last index of the same" "Or maybe the last index of the same"
(= __ (.lastIndexOf "hello world, hello" "hello")) (= __ (string/last-index-of "hello world, hello" "hello"))
"But when something doesn't exist, it turns up negative" "But when something doesn't exist, nothing is found"
(= __ (.indexOf "hello world" "bob")) (= __ (string/index-of "hello world" "bob"))
"Sometimes you don't want whitespace cluttering the front and back" "Sometimes you don't want whitespace cluttering the front and back"
(= __ (string/trim " \nhello world \t \n")) (= __ (string/trim " \nhello world \t \n"))