-
Notifications
You must be signed in to change notification settings - Fork 260
[SUGGESTION] Less Noised Interpolated Raw String Literals #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The only thing I find problematic about this proposal is how we escape the |
Interpolated Raw String Literals are already added to C++2 with notation We don't need to escape the
But if we want to escape only a single
Also if we want to escape
For the above example in C#, they allow optional new-lines to escape
In a nutshell, instead of allowing optional new-lines (like in C#), if both
Already in C++1 if multiple string literals |
Alternative SuggestionThis is an alternative suggestion, in the case you don't think the original suggestion is well suited for C++2. First I have to mention we need to force programmers to use escape sequence for
And multiple
By changing the notation of interpolated raw string literals from the original suggestion
Also the content of string literals can have characters
And it can be empty:
And these string literals can be placed side-by-side, C++2 will concatenate them, however it would be ugly and there is no need for that, compare how
The whole point of my suggestion is to have a simpler way to write interpolated raw string literals, syntax doesn't matter. This part is not suggested, but it can be an optionAlso the notation of non-interpolated raw string literals may change from
The
The interpolated raw string literals may have additional characters instead of
But
In addition C++2 may have a non-interpolated non-raw string literal:
|
OK, I feel I need to summerize my final suggestion in a new issue, so everyone can directly get my suggestion without too much thinking and reading. |
Currently
$R
prefix is used to quote interpolated raw string literals in C++2, e.g.$R"(text)"
.Template String Literals
Before I start to explain about my suggestion, I should mention that we don't have an empty character literal, therefore
''
is a syntax error in C++1. Instead of being a syntax error, I suggest to make''
the start and end of interpolated raw string literals:To write multiple single quotes
'
inside interpolated raw string literals, we can start and end them with more'
characters:NOTE 1: Also if they are placed side-by-side, then they will be concatenated with normal string literals (because they both are interpolated), that's the other reason why I suggested
''
instead of"""
(in languages such as C#) for them to be easily distinguishable when they are placed side-by-side. To have'
as a character at the begining or end in the content of interpolated raw string literals, we concatenate them with normal string literals instead of allowing optional separators such as new-lines (like in C#) or white-spaces (like in Markdown) between content and quotes. More examples:Finally, I have to mention that interpolated raw string literals are not a real raw... maybe we should define a new term for it, something like Interpolated Non-escape-sequenced String Literals. Simply we can call them Template String Literals.
Just like character literals, interpolated raw string literals cannot be empty, becuase multiple
'
characters (such as''
or'''
) always form the beginning of a string literal:My suggestion in a nutshell
Why do I suggest this change?
R"(text)"
is a powerfull raw string literal, but most of the time we just want to disable escape sequences and be able to simply write single quotes'
and double quotes"
inside a string literal. Simply we can call them Template String Literals. Using''
is more readable and more convenient with less typing than$R"(
to start an interpolated raw string literal.Also
''
is a syntax error in C++1 becuase we don't have an empty character literal in C++, therefore we can use this never used potential syntax, and programmers won't ask why''
doesn't work (becuase someone may think it should be a null character), they simply learn''
is the start and end of an interpolated raw (non-escape-sequenced) string literal.We can categorize string literals in a way that
''
is visually similar to"
, both''text''
(without escape sequences) and"text"
(with escape sequences) are interpolated string literals because they haven't a prefix, butR"(...)"
is non-interpolated non-escape-sequenced (real raw) string literal because it's prefixed withR
and has paranthesis for more complex texts.Is there any exprience, data or working implementation available?
My suggestion is similar to raw string literals in C# programming language, but C# 11 uses at least triple double quotes to start and end raw string literals, e.g.
"""A raw string literal in C# 11"""
. The first and last new-lines of the content won't be ignored in my suggestion, becuase C++2 can concatenate side-by-side interpolated string literals (see NOTE 1 and the example code), but in C# we have to put the content in a separate line if we want to start the content with"
, except that everything is the same.Also my suggestion is similar to inline code in Markdown launguage, but it uses at least a backtick
`
instead of double single quotes''
, except that everything is the same.I have to mention Python have triple single quotes
'''
and triple double quotes"""
for multi-line string literals.Literally experiences from C#, Python and Markdown languages can be reviewed.
The text was updated successfully, but these errors were encountered: