summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Liebke and Stuart Halloway <pair@clojure.com>2010-05-28 15:27:53 -0400
committerStuart Halloway <stu@thinkrelevance.com>2010-06-03 21:20:59 -0400
commit723991c12a4d12ef1dc4f5ab205e6f2a741faf33 (patch)
treeb96ed8533e274ce901129835e888aca86ee27c3e /src
parentf4427c70bd7c711b3a9c49f0a2e5f6781be707e1 (diff)
arg order fix, rename chomp-> trim-nl, drop chop, perf
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/string.clj23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/clj/clojure/string.clj b/src/clj/clojure/string.clj
index 8ad33608..e47bb4bf 100644
--- a/src/clj/clojure/string.clj
+++ b/src/clj/clojure/string.clj
@@ -118,26 +118,23 @@
(defn ^String triml
"Removes whitespace from the left side of string."
[^String s]
- (replace-re #"^\s+" "" s))
+ (replace s #"^\s+" ""))
(defn ^String trimr
"Removes whitespace from the right side of string."
[^String s]
- (replace-re #"\s+$" "" s))
+ (replace s #"\s+$" ""))
-(defn ^String chop
- "Removes the last character of string, does nothing on a zero-length
- string."
- [^String s]
- (let [size (count s)]
- (if (zero? size)
- s
- (subs s 0 (dec (count s))))))
-
-(defn ^String chomp
+(defn ^String trim-nl
"Removes all trailing newline \\n or return \\r characters from
string. Note: String.trim() is similar and faster."
[^String s]
- (replace-re #"[\r\n]+$" "" s))
+ (loop [offset (.length s)]
+ (if (zero? offset)
+ ""
+ (let [ch (.charAt s (dec offset))]
+ (if (or (= ch \newline) (= ch \return))
+ (recur (dec offset))
+ (.substring s 0 offset))))))