String reboot - (1a) incidental whitespace

Brian Goetz brian.goetz at oracle.com
Wed Apr 17 18:40:13 UTC 2019


Where this makes a difference is:

String s = “””
               I am 
                   a block of text
           “””;

Under Version 1, we would get:

I am
    a block of text

Under version 2, we would get

    I am 
        a block of text

Under version 1, if we wanted the latter answer, we would have to do .indent(4) or something like that.  


> On Apr 17, 2019, at 2:33 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
> 
>> 
>> I'm sorry I'm not completely caught up on this discussion yet and may have missed something. But I'm confused what the alternative to using the closing delimiter position is. You certainly don't want to magically use the column position of the *opening* delimiter in this example!  That is *definitely* incidental, as it depends on what the `query` variable got renamed to later by some refactoring tool. Variable renames shouldn't change program behavior.
>> 
> 
> Version 1 of the algorithm is:
>  - Strip leading and trailing blanks (perhaps limited to one each only)
>  - Compute the maximal common whitespace prefix of the remaining lines, and trim that off each line
>  - If a blank last line was trimmed, add back a newline
> 
> Version 2 of the algorithm — the “significant closing delimiter” version — is:
>  - Strip leading and trailing blanks (perhaps limited to one each only)
>  - Compute the maximal common whitespace prefix of the remaining lines, _including the stripped trailing blank line from above, if any_, and trim that off
>  - If a blank last line was trimmed, add back a newline
> 
> In other words, the difference is wether we strip off the trailing blank before or after we compute the leading whitespace prefix.  In neither case do we use scanner position.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20190417/4735d547/attachment-0001.html>


More information about the amber-spec-experts mailing list