Raw String Literals (RSL) - indent stripping of multi-line strings

Jim Laskey james.laskey at oracle.com
Fri Apr 27 01:04:06 UTC 2018

> - only remove leading whitespace of a determining line if the line's leading whitespace is the same sequence of spaces and tabs used on the representative line deemed to have the least amount of leading whitespace
>> Holy moly, I had completely overlooked bullet #2. This whole time I have been under the impression that stripIndent() can not yield a result where every nonblank line retains nonzero indentation. We were studying the 5% of our use cases that need this behavior and fretting... but they are actually going to be fine, it appears. Nice.

I jumped the gun on this and immediately realized (doh) that this requirement is not possible to implement cleanly.  Simple example (. == space,  | == tab);

String s = `
....line one
||||line two`;

What is the representative line in this case? If you have a mixture of white space characters then it may not be possible to get a representative line. Stuart and I discussed this and we came to the conclusion that you have to treat all white space characters equally (we can not in the tab war business), which leads us back to the original implementation with the following added to the JavaDoc;

     * This method works with all {@link Character#isWhitespace(int)}
     * white space characters as long as the leading white space is
     * consistent on all lines.  Otherwise, the result is indeterminant.

Note: indeterminant doesn’t always mean messy.


— Jim

More information about the amber-dev mailing list