Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8223775

String::stripIndent (Preview)

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 13
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b25
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        The _re-indentation algorithm_ takes a text block and removes the same amount of white space from each line of content until at least one of the lines has a non-white space character in the leftmost position. The algorithm is as follows:

        1. Split the content of the multi-line string at every LF, producing a list of _individual lines_. Note that any line in the content which was just an LF will become an empty line in the list of individual lines.

        2. Add all _non-blank_ lines from the list of individual lines into a set of _determining lines_. (Blank lines -- lines that are empty or are composed wholly of white space -- should exert no influence on the result. Excluding them from the set of determining lines avoids throwing off step 4 of the algorithm.)

        3. If the last line in the list of individual lines (i.e., the line with the text block closing delimiter) is _blank_, then add it to the set of determining lines. (The indentation of the closing delimiter should influence the indentation of the content as a whole -- a "significant trailing line" policy.)

        4. Compute the _common white space prefix_ of the set of determining lines, by counting the number of leading white space characters on each line and taking the minimum count.

        5. Remove the common white space prefix from each _non-blank_ line in the list of individual lines.

        6. Remove all trailing white space from all lines in the modified list of individual lines from step 5. ("Hidden" white space at the end of lines is unintentional, so it is overwhelmingly likely that the developer does _not_ want it in the string.) Note that this step collapses wholly-white space lines in the modified list so that they are empty, but does not discard them.

        7. Construct the result string by joining all the lines in the modified list of individual lines from step 6, using LF as the separator between lines. If the final line in the list from step 6 is empty, then that line is discarded when joining, and does not appear in the result string.

        This re-indentation algorithm will be referenced in normative text by the new JLS section for text blocks (see http://cr.openjdk.java.net/~abuckley/jep355/text-blocks-jls.html). In other words, the JLS will logically incorporate the API spec of String::stripIndent, but will not physically incorporate it.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  jlaskey Jim Laskey
                  Reporter:
                  jlaskey Jim Laskey
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: