summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Bileschi <mbileschi@twitter.com>2014-08-26 13:05:18 -0400
committerAdriaan Moors <adriaan.moors@typesafe.com>2014-10-07 10:39:31 +0200
commitefbef1e02c067420005df5e862405c0a5e4f8df3 (patch)
tree9db8de5124d6c29476b17413e85a1dfb46a962bd /src
parentd028d89ece11a886cce88e2c0e1d8443d6271e0c (diff)
downloadscala-efbef1e02c067420005df5e862405c0a5e4f8df3.tar.gz
scala-efbef1e02c067420005df5e862405c0a5e4f8df3.tar.bz2
scala-efbef1e02c067420005df5e862405c0a5e4f8df3.zip
Update stripPrefix/StringLike docs to talk about no op case
Incorporate review comments by Som Snytt.
Diffstat (limited to 'src')
-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