Page MenuHomePhabricator

[clang-format] Handle escaped " in C# string-literals
ClosedPublic

Authored by jbcoe on Jan 24 2020, 7:13 AM.

Diff Detail

Event Timeline

jbcoe created this revision.Jan 24 2020, 7:13 AM
krasimir marked an inline comment as done.Jan 24 2020, 7:25 AM
krasimir added inline comments.
clang/lib/Format/FormatTokenLexer.cpp
197

This merging is only valid if CSharpStringLiteral starts with @" or with $@"; if the literal stars with $", it's invalid.
Consider this example:
$"""Hello"
In this case these really are 2 different tokens (I don't know C# so I might be wrong, but vim syntax highlighting suggests this).

Consider also adding tests for these combinations.

213

Nice catch!

krasimir added inline comments.Jan 24 2020, 7:27 AM
clang/unittests/Format/FormatTestCSharp.cpp
415

maybe add an example where these are applied a couple of times, like in @"""Hello, world""" (to make sure the state of the token stream after the merging is good).

jbcoe updated this revision to Diff 240211.Jan 24 2020, 8:07 AM

Extend tests and explicit check for verbatim strings not just C# string literals.

jbcoe marked 2 inline comments as done.Jan 24 2020, 8:08 AM
krasimir accepted this revision.Jan 24 2020, 8:09 AM

Thank you!
Should I commit this for you?

This revision is now accepted and ready to land.Jan 24 2020, 8:09 AM
jbcoe added a comment.Jan 24 2020, 8:53 AM

@krasimir Would be great if you could commit this.

MyDeveloperDay added a project: Restricted Project.Jan 26 2020, 2:18 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2020, 3:58 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript