aboutsummaryrefslogtreecommitdiff
path: root/modules/repl-utils/src/main/clojure
diff options
context:
space:
mode:
authorBen Smith-Mannschott <bsmith.occs@gmail.com>2010-08-28 11:22:22 +0200
committerStuart Sierra <mail@stuartsierra.com>2010-09-03 12:23:37 -0400
commitfe4ed311166677cd571d23774171af1d830f7fc5 (patch)
tree70d6c519b8afa7bbee51bb8c3e243d4f3903b2e2 /modules/repl-utils/src/main/clojure
parent034d3d1703d139117b38fe6a10f552e23aa48b5c (diff)
remove deprecated clojure.contrib.string
Since clojure.contrib.string is used by other submodules, some changes were required: - gen-html-docs and prxml needed changes because of functions were renamed or arguments reordered when promoted to clojure.string. - jmx, json, miglayout, prxml and sql gained a private one-argument implementation of as-str. - repl-utils gained a private copy of c.c.string/partition, named spartition. - repl-utils replaced a call to c.c.string/substring? with a call to the java String method '.contains' (with swapped argument order). Signed-off-by: Stuart Sierra <mail@stuartsierra.com>
Diffstat (limited to 'modules/repl-utils/src/main/clojure')
-rw-r--r--modules/repl-utils/src/main/clojure/clojure/contrib/repl_utils.clj33
1 files changed, 27 insertions, 6 deletions
diff --git a/modules/repl-utils/src/main/clojure/clojure/contrib/repl_utils.clj b/modules/repl-utils/src/main/clojure/clojure/contrib/repl_utils.clj
index bc9787b5..39195ea0 100644
--- a/modules/repl-utils/src/main/clojure/clojure/contrib/repl_utils.clj
+++ b/modules/repl-utils/src/main/clojure/clojure/contrib/repl_utils.clj
@@ -18,23 +18,44 @@
(:import (java.io File LineNumberReader InputStreamReader PushbackReader)
(java.lang.reflect Modifier Method Constructor)
(clojure.lang RT Compiler Compiler$C))
- (:require [clojure.contrib.string :as s])
(:use [clojure.contrib.seq :only (indexed)]
- [clojure.java.browse :only (browse-url)]))
+ [clojure.java.browse :only (browse-url)]
+ [clojure.string :only (join)]))
;; ----------------------------------------------------------------------
;; Examine Java classes
+(defn- spartition
+ "Splits the string into a lazy sequence of substrings, alternating
+ between substrings that match the patthern and the substrings
+ between the matches. The sequence always starts with the substring
+ before the first match, or an empty string if the beginning of the
+ string matches.
+
+ For example: (spartition #\"[a-z]+\" \"abc123def\")
+ returns: (\"\" \"abc\" \"123\" \"def\")"
+ [^Pattern re ^String s]
+ (let [m (re-matcher re s)]
+ ((fn step [prevend]
+ (lazy-seq
+ (if (.find m)
+ (cons (.subSequence s prevend (.start m))
+ (cons (re-groups m)
+ (step (+ (.start m) (count (.group m))))))
+ (when (< prevend (.length s))
+ (list (.subSequence s prevend (.length s)))))))
+ 0)))
+
(defn- sortable [t]
(apply str (map (fn [[a b]] (str a (format "%04d" (Integer. b))))
- (partition 2 (concat (s/partition #"\d+" t) [0])))))
+ (spartition 2 (concat (spartition #"\d+" t) [0])))))
(defn- param-str [m]
- (str " (" (s/join
+ (str " (" (join
"," (map (fn [[c i]]
(if (> i 3)
(str (.getSimpleName c) "*" i)
- (s/join "," (replicate i (.getSimpleName c)))))
+ (join "," (replicate i (.getSimpleName c)))))
(reduce (fn [pairs y] (let [[x i] (peek pairs)]
(if (= x y)
(conj (pop pairs) [y (inc i)])
@@ -138,7 +159,7 @@ str-or-pattern."
[str-or-pattern]
(let [matches? (if (instance? java.util.regex.Pattern str-or-pattern)
#(re-find str-or-pattern (str %))
- #(s/substring? (str str-or-pattern) (str %)))]
+ #(.contains (str %) (str str-or-pattern)))]
(mapcat (fn [ns]
(filter matches? (keys (ns-publics ns))))
(all-ns))))