diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-10-07 13:45:41 +0200 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-10-07 13:45:41 +0200 |
commit | cd46dc31140b73eec08b04916310d316aa2df3ea (patch) | |
tree | 9307b7c2e107557bbd6f6226ceba9ea8fa9fe556 | |
parent | 47ab999de2c21ceb7a3c9180b972010d63d5df0f (diff) | |
parent | efbef1e02c067420005df5e862405c0a5e4f8df3 (diff) | |
download | scala-cd46dc31140b73eec08b04916310d316aa2df3ea.tar.gz scala-cd46dc31140b73eec08b04916310d316aa2df3ea.tar.bz2 scala-cd46dc31140b73eec08b04916310d316aa2df3ea.zip |
Merge pull request #4034 from adriaanm/pr-3950-rework
Update stripPrefix/StringLike docs to talk about no op case
-rw-r--r-- | src/library/scala/collection/immutable/StringLike.scala | 12 |
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 |