- Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Java multiline blocks supports \s
escape sequence.
https://docs.oracle.com/en/java/javase/21/text-blocks/index.html
The \s escape sequence simple translates to space (\040, ASCII character 32, white space.) Since escape sequences don't get translated until after incident space stripping, \s can act as fence to prevent the stripping of trailing white space. Using \s at the end of each line in the following example, guarantees that each line is exactly six characters long.
String colors = """ red \s green\s blue \s """;
Scala doesn't support \s
escape sequence.
Scala 2 compiler crashes
Scala 3 compiler says
invalid escape '\s' not one of [\b, \t, \n, \f, \r, \, ", ', \uxxxx] at index 4 in "aaa \s bbb". Use \ for literal .
Given that \s
is not reserved, the compiler could support by simply replacing with \s
At first glance, this should be trivial to fix.
This wouldn't work in non-interpolated multiline string literals and in raw string literals because they don't support escape sequences.
Still, it could still be a nice addition.