From efbef1e02c067420005df5e862405c0a5e4f8df3 Mon Sep 17 00:00:00 2001 From: Max Bileschi Date: Tue, 26 Aug 2014 13:05:18 -0400 Subject: Update stripPrefix/StringLike docs to talk about no op case Incorporate review comments by Som Snytt. --- src/library/scala/collection/immutable/StringLike.scala | 12 +++++++++--- 1 file 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 -- cgit v1.2.3