Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8230800: Clarify String::stripIndent javadoc when string ends with li…
…ne terminator

Reviewed-by: jlaskey, bchristi, rriggs
  • Loading branch information
JimLaskey committed Jun 1, 2020
1 parent 7467cd2 commit bfd2e96120260c344e31393b1da112aed94aacfb
Showing with 27 additions and 16 deletions.
  1. +27 −16 src/java.base/share/classes/java/lang/String.java
@@ -2917,22 +2917,34 @@ private int lastIndexOfNonWhitespace() {
* | </body>
* |</html>
* </pre></blockquote>
* First, the individual lines of this string are extracted as if by using
* {@link String#lines()}.
* First, the individual lines of this string are extracted. A <i>line</i>
* is a sequence of zero or more characters followed by either a line
* terminator or the end of the string.
* If the string has at least one line terminator, the last line consists
* of the characters between the last terminator and the end of the string.
* Otherwise, if the string has no terminators, the last line is the start
* of the string to the end of the string, in other words, the entire
* string.
* A line does not include the line terminator.
* <p>
* Then, the <i>minimum indentation</i> (min) is determined as follows.
* For each non-blank line (as defined by {@link String#isBlank()}), the
* leading {@linkplain Character#isWhitespace(int) white space} characters are
* counted. The leading {@linkplain Character#isWhitespace(int) white space}
* characters on the last line are also counted even if
* {@linkplain String#isBlank() blank}. The <i>min</i> value is the smallest
* of these counts.
* Then, the <i>minimum indentation</i> (min) is determined as follows:
* <ul>
* <li><p>For each non-blank line (as defined by {@link String#isBlank()}),
* the leading {@linkplain Character#isWhitespace(int) white space}
* characters are counted.</p>
* </li>
* <li><p>The leading {@linkplain Character#isWhitespace(int) white space}
* characters on the last line are also counted even if
* {@linkplain String#isBlank() blank}.</p>
* </li>
* </ul>
* <p>The <i>min</i> value is the smallest of these counts.
* <p>
* For each {@linkplain String#isBlank() non-blank} line, <i>min</i> leading
* {@linkplain Character#isWhitespace(int) white space} characters are removed,
* and any trailing {@linkplain Character#isWhitespace(int) white space}
* characters are removed. {@linkplain String#isBlank() Blank} lines are
* replaced with the empty string.
* {@linkplain Character#isWhitespace(int) white space} characters are
* removed, and any trailing {@linkplain Character#isWhitespace(int) white
* space} characters are removed. {@linkplain String#isBlank() Blank} lines
* are replaced with the empty string.
*
* <p>
* Finally, the lines are joined into a new string, using the LF character
@@ -2943,12 +2955,11 @@ private int lastIndexOfNonWhitespace() {
* possible to the left, while preserving relative indentation. Lines
* that were indented the least will thus have no leading
* {@linkplain Character#isWhitespace(int) white space}.
* The line count of the result will be the same as line count of this
* string.
* The result will have the same number of line terminators as this string.
* If this string ends with a line terminator then the result will end
* with a line terminator.
*
* @implNote
* @implSpec
* This method treats all {@linkplain Character#isWhitespace(int) white space}
* characters as having equal width. As long as the indentation on every
* line is consistently composed of the same character sequences, then the

0 comments on commit bfd2e96

Please sign in to comment.