Skip to content
Browse files

trim variants differ by suffix, for sortability

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information...
1 parent 4997e80 commit 8c0022f29cc3ddc6cfb8b1cacd8839425620b18d David Liebke and Stuart Halloway committed with stuarthalloway May 28, 2010
Showing with 32 additions and 31 deletions.
  1. +26 −25 src/clj/clojure/string.clj
  2. +6 −6 test/clojure/test_clojure/string.clj
View
51 src/clj/clojure/string.clj
@@ -82,21 +82,6 @@
sep)
(str sb)))))
-(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
- "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))
-
(defn ^String capitalize
"Converts first character of the string to upper-case, all other
characters to lower-case."
@@ -106,16 +91,6 @@
(str (.toUpperCase ^String (subs s 0 1))
(.toLowerCase ^String (subs s 1)))))
-(defn ^String ltrim
- "Removes whitespace from the left side of string."
- [^String s]
- (replace-re #"^\s+" "" s))
-
-(defn ^String rtrim
- "Removes whitespace from the right side of string."
- [^String s]
- (replace-re #"\s+$" "" s))
-
(defn ^String upper-case
"Converts string to all upper-case."
[^String s]
@@ -137,3 +112,29 @@
[^String s]
(.trim s))
+(defn ^String triml
+ "Removes whitespace from the left side of string."
+ [^String s]
+ (replace-re #"^\s+" "" s))
+
+(defn ^String trimr
+ "Removes whitespace from the right side of string."
+ [^String s]
+ (replace-re #"\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
+ "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))
+
+
View
12 test/clojure/test_clojure/string.clj
@@ -41,13 +41,13 @@
(is (= "Foobar" (s/capitalize "foobar")))
(is (= "Foobar" (s/capitalize "FOOBAR"))))
-(deftest t-ltrim
- (is (= "foo " (s/ltrim " foo ")))
- (is (= "" (s/ltrim " "))))
+(deftest t-triml
+ (is (= "foo " (s/triml " foo ")))
+ (is (= "" (s/triml " "))))
-(deftest t-rtrim
- (is (= " foo" (s/rtrim " foo ")))
- (is (= "" (s/rtrim " "))))
+(deftest t-trimr
+ (is (= " foo" (s/trimr " foo ")))
+ (is (= "" (s/trimr " "))))
(deftest t-trim
(is (= "foo" (s/trim " foo \r\n"))))

0 comments on commit 8c0022f

Please sign in to comment.
Something went wrong with that request. Please try again.