Raw strings starting/ending with backtick
cay.horstmann at sjsu.edu
Sun Nov 25 07:39:39 UTC 2018
I agree that it is inelegant that there is no good syntax for raw
strings starting with a backtick. Some time ago
(http://horstmann.com/unblog/2018-06-01), I suggested that an initial
newline after the backticks could count as part of the raw string delimiter:
String myNameInABox = ```
| Cay |
+-----+```; // This string starts with +
Ok, maybe it's not brilliant, but it solves two problems: (1) how to
format multiline strings that should be aligned, without having to strip
out the initial newline (2) how to declare strings that start with a
Le 24/11/2018 à 18:57, Attila Kelemen a écrit :
> Thanks for all the answers. I was just a little curious if I missed
> something and there is nice syntax for this as well. Not that I could
> come up with something brilliant, only if Java was a brand new language,
> then 3 "quote" types would solve all the issues (and escaping would be
> completely useless). Obviously, this is not really an option here.
> James Laskey <james.laskey at oracle.com <mailto:james.laskey at oracle.com>>
> ezt írta (időpont: 2018. nov. 24., Szo, 18:30):
> Sent from my iPhone
> > On Nov 24, 2018, at 11:34 AM, Weijun Wang <weijun.wang at oracle.com
> <mailto:weijun.wang at oracle.com>> wrote:
> >> On Nov 24, 2018, at 9:11 PM, Jim Laskey <james.laskey at oracle.com
> <mailto:james.laskey at oracle.com>> wrote:
> >> There are several approaches but the simplest is using
> strip(). Example,
> >> `` `abc` ``.strip()
> >> Concat is another approach,
> >> “`” + `abc` + “`”
> > But this means the literal inside the constant pool of the class
> will be "`abc` ", right? This is a little uncomfortable to me.
> That’s the plan.
> >> Not perfect but other delimiter choices also have these edge cases.
> > How about the Rust r###"..."### style?
> > Thanks
> > Max
> >> Cheers,
> >> — Jim
> >> Sent from my iPad
> >>> On Nov 24, 2018, at 8:55 AM, Attila Kelemen
> <attila.kelemen85 at gmail.com <mailto:attila.kelemen85 at gmail.com>> wrote:
> >>> Hi,
> >>> Reading the JEP on raw string literals, I saw no mentions of
> the case when a string starts (or ends) with backtick. I guessed,
> that maybe the compiler will close the literal when it finds more
> than half the number of backticks than the beginning (nothing
> implied this behaviour just tried it and I know that it might be
> very suprising in other cases). I have tried with the latest early
> access compiler and (not too suprisingly) it didn't behave this way
> and simply failed when starting the literal with a backtick.
> >>> My question is, of course: What is the strategy for this case?
> Or is it explicitly ignored as too much of an edge case (and left to
> the developer to deal with)?
> >>> Thanks,
> >>> Attila Kelemen
Cay S. Horstmann | http://horstmann.com | mailto:cay at horstmann.com
More information about the compiler-dev