Skip to content

Commit 8c8fc40

Browse files
code review of #359: pass in CharSequence, but return String
Signed-off-by: Stuart Halloway <[email protected]>
1 parent 4860f9e commit 8c8fc40

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/clj/clojure/string.clj

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ clojure.string adheres to the following design principles:
3131
(:import (java.util.regex Pattern)
3232
clojure.lang.LazilyPersistentVector))
3333

34-
(defn ^CharSequence reverse
34+
(defn ^String reverse
3535
"Returns s with its characters reversed."
3636
{:added "1.2"}
3737
[^CharSequence s]
@@ -48,7 +48,7 @@ clojure.string adheres to the following design principles:
4848
(do (.appendTail m buffer)
4949
(.toString buffer)))))))
5050

51-
(defn replace
51+
(defn ^String replace
5252
"Replaces all instance of match with replacement in s.
5353
5454
match/replacement can be:
@@ -72,7 +72,7 @@ clojure.string adheres to the following design principles:
7272
(defn- replace-first-by
7373
[^CharSequence s ^Pattern re f]
7474
(let [m (re-matcher re s)]
75-
(let [buffer (StringBuffer.)]
75+
(let [buffer (StringBuffer. (.length s))]
7676
(if (.find m)
7777
(let [rep (f (re-groups m))]
7878
(.appendReplacement m buffer rep)
@@ -87,7 +87,7 @@ clojure.string adheres to the following design principles:
8787
s
8888
(str (subs s 0 i) replace (subs s (inc i))))))
8989

90-
(defn replace-first
90+
(defn ^String replace-first
9191
"Replaces the first instance of match with replacement in s.
9292
9393
match/replacement can be:
@@ -114,7 +114,7 @@ clojure.string adheres to the following design principles:
114114
:else (throw (IllegalArgumentException. (str "Invalid match arg: " match))))))
115115

116116

117-
(defn ^CharSequence join
117+
(defn ^String join
118118
"Returns a string of all elements in coll, separated by
119119
an optional separator. Like Perl's join."
120120
{:added "1.2"}
@@ -130,7 +130,7 @@ clojure.string adheres to the following design principles:
130130
sep)
131131
(str sb)))))
132132

133-
(defn ^CharSequence capitalize
133+
(defn ^String capitalize
134134
"Converts first character of the string to upper-case, all other
135135
characters to lower-case."
136136
{:added "1.2"}
@@ -141,13 +141,13 @@ clojure.string adheres to the following design principles:
141141
(str (.toUpperCase (subs s 0 1))
142142
(.toLowerCase (subs s 1))))))
143143

144-
(defn ^CharSequence upper-case
144+
(defn ^String upper-case
145145
"Converts string to all upper-case."
146146
{:added "1.2"}
147147
[^CharSequence s]
148148
(.. s toString toUpperCase))
149149

150-
(defn ^CharSequence lower-case
150+
(defn ^String lower-case
151151
"Converts string to all lower-case."
152152
{:added "1.2"}
153153
[^CharSequence s]
@@ -162,13 +162,13 @@ clojure.string adheres to the following design principles:
162162
([ ^CharSequence s ^Pattern re limit]
163163
(LazilyPersistentVector/createOwning (.split re s limit))))
164164

165-
(defn ^CharSequence trim
165+
(defn ^String trim
166166
"Removes whitespace from both ends of string."
167167
{:added "1.2"}
168168
[^CharSequence s]
169169
(.. s toString trim))
170170

171-
(defn ^CharSequence triml
171+
(defn ^String triml
172172
"Removes whitespace from the left side of string."
173173
{:added "1.2"}
174174
[^CharSequence s]
@@ -179,7 +179,7 @@ clojure.string adheres to the following design principles:
179179
(recur (inc index))
180180
(.. s (subSequence index (.length s)) toString)))))
181181

182-
(defn ^CharSequence trimr
182+
(defn ^String trimr
183183
"Removes whitespace from the right side of string."
184184
{:added "1.2"}
185185
[^CharSequence s]
@@ -190,7 +190,7 @@ clojure.string adheres to the following design principles:
190190
(recur (dec index))
191191
(.. s (subSequence 0 index) toString)))))
192192

193-
(defn ^CharSequence trim-newline
193+
(defn ^String trim-newline
194194
"Removes all trailing newline \\n or return \\r characters from
195195
string. Similar to Perl's chomp."
196196
{:added "1.2"}

0 commit comments

Comments
 (0)