[PATCH] Better support for multiline string literals (including C++11 raw string literals).

Alexander Kornienko alexfh at google.com
Thu Aug 29 10:06:31 PDT 2013



================
Comment at: lib/Format/ContinuationIndenter.h:87
@@ -86,1 +86,3 @@
 
+  unsigned addMultilineStringLiteral(const FormatToken &Current,
+                                     LineState &State);
----------------
Daniel Jasper wrote:
> comment
Done.

================
Comment at: lib/Format/ContinuationIndenter.cpp:586
@@ +585,3 @@
+  StringRef Text = Current.TokenText;
+  size_t FirstLineBreak = Text.find('\n');
+  size_t LastLineBreak = Text.find_last_of('\n');
----------------
Daniel Jasper wrote:
> Add a comment saying that we do not have to look at/penalize the lengths of any but the first line as they are outside of clang-format's influence anyway.
Done.

================
Comment at: lib/Format/ContinuationIndenter.cpp:620
@@ +619,3 @@
+    if (Current.TokenText.find('\n') != StringRef::npos)
+      return addMultilineStringLiteral(Current, State);
+
----------------
Daniel Jasper wrote:
> It seems bad to call Current.TokenText.find('\n') again in addMultilineStringLiteral (and even assert on the result). How about just passing this in?
I've introduced FormatToken::IsMultiline so that we don't search for \n here each time.

================
Comment at: lib/Format/ContinuationIndenter.cpp:623
@@ -595,3 +622,3 @@
     // Only break up default narrow strings.
     if (!Current.TokenText.startswith("\""))
       return 0;
----------------
Daniel Jasper wrote:
> Why not still do this first? Seems to be the faster operation.
Addressed by IsMultiline.


http://llvm-reviews.chandlerc.com/D1544

BRANCH
  svn

ARCANIST PROJECT
  clang



More information about the cfe-commits mailing list