Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are line breaks in raw strings platform-dependent?

Are line breaks in raw strings platform-dependent?

val a = "one\ntwo";

val b = """one
two"""

println(a == b)

In other words, is the println statement above guaranteed to print true or not?

like image 853
fredoverflow Avatar asked Nov 07 '22 15:11

fredoverflow


1 Answers

Unfortunately, I couldn't find any sources specifically stating this. It feels like something that should be in the docs.

There is, however, the intention action in IntelliJ that converts a raw string to an ordinary string. I think it should be safe to assume that this action should not change the meaning of your code (or if it does, that should be filed as a bug). If you try this on a raw string with a newline in it, you can see that it replaces the newline with a \n character.

You can see the source of the action here, and a test for it that expects it to convert the newline to \n here (before) and here (after).


Edit: here's a comment on an issue about raw strings that (as far as I understand) states that a raw string has \n line endings in it.

like image 191
zsmb13 Avatar answered Nov 14 '22 21:11

zsmb13