Multiline string literals: can we get rid of the need for stripMargin?

Could we use the closing """ position instead of counting the spaces for each line? It would strip as many spaces as before closing """. If it went past any non-space character it would be compile error.
I’d love tabs to be a compiletime error also. :grin:

EDIT:
Seems like Java 14 forces \s*\n on opening triplequote, e.g. these don’t work:
""" test """

""" test
"""

This does:

""" 
test"""

I like this because it makes handling of first line easier. We just ignore it… :smiley:
I don’t like it strips trailling whitespace though. It has its usecases like Markdown, where space at end of line is significant!
Try here https://tryjshell.org/


In summary, these would be nice:

  • force blanks+newline after opening triplequote
  • force newline+blanks before closing triplequote
  • use closing triplequote as index of how many spaces to remove
2 Likes