Fleshgrinder
04/10/2021, 4:46 PM\n
vs \r\n
). Basically what we should have:
println("""\
This is the first line in this \
multi-line string.
This is the second line in this \
multi-line string.
""")
The above would result in:
This is the first line in this multi-line string.
This is the second line in this multi-line string.
I guess the fact that the backslash has no special meaning in multi-line strings today would be a blocker for this, because it suddenly would need to be escaped and existing code would break. At the same time it would have been nice to use it as escaper so that we could simply write \$
instead of ${'$'}
but too late. I fear an alternative approach is needed here. Maybe f""
for a multi-line string with normal escape behavior (so \"
needs to be used). 🤔 Anyways, just wanted to get this off my chest.ephemient
04/10/2021, 4:50 PM.trimMargin()
-like approach: write your strings with an explicit | denoting the intentional start of a line, and create a String
extension to strip everything else awayFleshgrinder
04/10/2021, 4:55 PMFleshgrinder
04/10/2021, 4:56 PM"""""".trimIndent().replace("(?<!\n)\n(?!\n)".toRegex(), " ")
Which obviously can have false positives.elouiscad
04/10/2021, 5:14 PMreplace("\\\n", "")
Fleshgrinder
04/10/2021, 5:23 PMreplace('\n', ' ')
but this will replace \n\n
and those are the ones I want to preserve. The Regex checks that it's a single \n
and replaces it with a space.Fleshgrinder
04/10/2021, 5:38 PMFleshgrinder
04/10/2021, 5:39 PM