Skip to content

Commit

Permalink
abstraction fix to split: preserve vector nature of host return value…
Browse files Browse the repository at this point in the history
… #359

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information
stuarthalloway committed Jun 4, 2010
1 parent 2c9503a commit 8ac69ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/clj/clojure/string.clj
Expand Up @@ -10,7 +10,8 @@
:author "Stuart Sierra"} :author "Stuart Sierra"}
clojure.string clojure.string
(:refer-clojure :exclude (replace reverse)) (:refer-clojure :exclude (replace reverse))
(:import (java.util.regex Pattern))) (:import (java.util.regex Pattern)
clojure.lang.LazilyPersistentVector))


(defn ^String reverse (defn ^String reverse
"Returns s with its characters reversed." "Returns s with its characters reversed."
Expand Down Expand Up @@ -123,10 +124,12 @@


(defn split (defn split
"Splits string on a regular expression. Optional argument limit is "Splits string on a regular expression. Optional argument limit is
the maximum number of splits." the maximum number of splits. Not lazy. Returns vector of the splits."
{:added "1.2"} {:added "1.2"}
([^Pattern re ^String s] (seq (.split re s))) ([^String s ^Pattern re]
([^Pattern re limit ^String s] (seq (.split re s limit)))) (LazilyPersistentVector/createOwning (.split re s)))
([ ^String s ^Pattern re limit]
(LazilyPersistentVector/createOwning (.split re s limit))))


(defn ^String trim (defn ^String trim
"Removes whitespace from both ends of string." "Removes whitespace from both ends of string."
Expand Down
5 changes: 5 additions & 0 deletions test/clojure/test_clojure/string.clj
Expand Up @@ -2,6 +2,11 @@
(:require [clojure.string :as s]) (:require [clojure.string :as s])
(:use clojure.test)) (:use clojure.test))


(deftest t-split
(is (= ["a" "b"] (s/split "a-b" #"-")))
(is (= ["a" "b-c"] (s/split "a-b-c" #"-" 2)))
(is (vector? (s/split "abc" #"-"))))

(deftest t-reverse (deftest t-reverse
(is (= "tab" (s/reverse "bat")))) (is (= "tab" (s/reverse "bat"))))


Expand Down

0 comments on commit 8ac69ed

Please sign in to comment.