diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2009-08-19 12:09:53 -0400 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2009-08-19 12:09:53 -0400 |
commit | b77d22fb567127edf5d3f5caebfbfbd9d7ce4ab2 (patch) | |
tree | b221d852bb750fb2a89bea583db5727b83b64bee | |
parent | 31ffb915af12133275f5ed6a67e312fc92635e7d (diff) |
str_utils2.clj: avoid error on zero-length string in chop
-rw-r--r-- | src/clojure/contrib/str_utils2.clj | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/clojure/contrib/str_utils2.clj b/src/clojure/contrib/str_utils2.clj index e5a541cf..b70a9ba4 100644 --- a/src/clojure/contrib/str_utils2.clj +++ b/src/clojure/contrib/str_utils2.clj @@ -233,9 +233,13 @@ (apply str (interpose separator coll))) (defn chop - "Removes the last character of string." + "Removes the last character of string, does nothing on a zero-length + string." [#^String s] - (subs s 0 (dec (count s)))) + (let [size (count s)] + (if (zero? size) + s + (subs s 0 (dec (count s)))))) (defn chomp "Removes all trailing newline \\n or return \\r characters from |