File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
src/library/scala/collection/immutable Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -135,23 +135,29 @@ self =>
135
135
def linesIterator : Iterator [String ] =
136
136
linesWithSeparators map (line => new WrappedString (line).stripLineEnd)
137
137
138
- /** Returns this string with first character converted to upper case */
138
+ /** Returns this string with first character converted to upper case.
139
+ * If the first character of the string is capitalized, it is returned unchanged.
140
+ */
139
141
def capitalize : String =
140
142
if (toString == null ) null
141
143
else if (toString.length == 0 ) " "
144
+ else if (toString.charAt(0 ).isUpper) toString
142
145
else {
143
146
val chars = toString.toCharArray
144
147
chars(0 ) = chars(0 ).toUpper
145
148
new String (chars)
146
149
}
147
150
148
- /** Returns this string with the given `prefix` stripped. */
151
+ /** Returns this string with the given `prefix` stripped. If this string does not
152
+ * start with `prefix`, it is returned unchanged.
153
+ */
149
154
def stripPrefix (prefix : String ) =
150
155
if (toString.startsWith(prefix)) toString.substring(prefix.length)
151
156
else toString
152
157
153
158
/** Returns this string with the given `suffix` stripped. If this string does not
154
- * end with `suffix`, it is returned unchanged. */
159
+ * end with `suffix`, it is returned unchanged.
160
+ */
155
161
def stripSuffix (suffix : String ) =
156
162
if (toString.endsWith(suffix)) toString.substring(0 , toString.length() - suffix.length)
157
163
else toString
You can’t perform that action at this time.
0 commit comments