summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/scala/collection/immutable/StringLike.scala12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala
index 738b294ce6..bf93a38f55 100644
--- a/src/library/scala/collection/immutable/StringLike.scala
+++ b/src/library/scala/collection/immutable/StringLike.scala
@@ -135,23 +135,29 @@ self =>
def linesIterator: Iterator[String] =
linesWithSeparators map (line => new WrappedString(line).stripLineEnd)
- /** Returns this string with first character converted to upper case */
+ /** Returns this string with first character converted to upper case.
+ * If the first character of the string is capitalized, it is returned unchanged.
+ */
def capitalize: String =
if (toString == null) null
else if (toString.length == 0) ""
+ else if (toString.charAt(0).isUpper) toString
else {
val chars = toString.toCharArray
chars(0) = chars(0).toUpper
new String(chars)
}
- /** Returns this string with the given `prefix` stripped. */
+ /** Returns this string with the given `prefix` stripped. If this string does not
+ * start with `prefix`, it is returned unchanged.
+ */
def stripPrefix(prefix: String) =
if (toString.startsWith(prefix)) toString.substring(prefix.length)
else toString
/** Returns this string with the given `suffix` stripped. If this string does not
- * end with `suffix`, it is returned unchanged. */
+ * end with `suffix`, it is returned unchanged.
+ */
def stripSuffix(suffix: String) =
if (toString.endsWith(suffix)) toString.substring(0, toString.length() - suffix.length)
else toString