Raw string new line enforcer #6800
Replies: 3 comments 9 replies
-
See: Verbatim and raw strings both do not process the characters within the literal (aside the escaping of double-quotes in the former). It's intentional that whatever newline character(s) are in the source file end up in the literal. It's been suggested to not use such tools as "autocrlf", honestly I don't think I've met an editor in Windows lately that doesn't understand just |
Beta Was this translation helpful? Give feedback.
-
That appears to be an issue with your source control system. It would affect normal strings as well. I would recommend not having other tools munge your source files. |
Beta Was this translation helpful? Give feedback.
-
Besides git source control issues, that can painfully be worked around, I believe there is a problem when the same bit of code is going to generate a different result depending on when and how the code is built. You can imagine someone copying code from the web and pasting it in their code editor of choice, and having the code behave differently on their machine, without it being explicitly obvious, as the encoding of line endings is invisible to our eyes. However, there are very specific scenarios in which this can be a problem, and I firmly believe that the developer should be able to explicitly enforce how his code is to be interpreted, so that the results can be guaranteed irrespective to the external circumstances. Example of such a scenario: A unit test is built on a windows machine using crlf line endings and run on a linux machine using lf line endings, and the test fails. It is in fact very weird that the compiler would have a specific interpretation of what is a line ending (if only for counting them and delimiting
See the above, I believe that de-indentation already counts as processing. It wouldn't be unreasonable to allow an optional mode that would provide a strict interpretation of line endings. ProposalRegarding the proposal here, I would have proposed to put the specifier as a suffix, as I tend to believe that it makes the syntax simpler and avoids introducing a keyword that would have a wide scope.
Generally, the rule if we ever need to have other specifiers similar to Examplevar s = """
Hello
World
"""u8lf;
Assert(s.Length == 11); |
Beta Was this translation helpful? Give feedback.
-
Raw string doesn’t allow setting the exact newline character.
This makes it harder to use it when anyone checks out code with automatic LF->CRLF conversion.
My suggestions is to add a feature making it clear.
(The actual syntax can be different)
Sample:
Beta Was this translation helpful? Give feedback.
All reactions