From b77d22fb567127edf5d3f5caebfbfbd9d7ce4ab2 Mon Sep 17 00:00:00 2001 From: Stuart Sierra Date: Wed, 19 Aug 2009 12:09:53 -0400 Subject: str_utils2.clj: avoid error on zero-length string in chop --- src/clojure/contrib/str_utils2.clj | 8 ++++++-- 1 file 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 -- cgit v1.2.3-18-g5258