Skip to content

Don't break multi-line strings - #14

Merged
davetcoleman merged 1 commit into
PickNikRobotics:masterfrom
zultron:fix-string-breaks
Mar 11, 2021
Merged

Don't break multi-line strings#14
davetcoleman merged 1 commit into
PickNikRobotics:masterfrom
zultron:fix-string-breaks

Conversation

@zultron

@zultron zultron commented Sep 20, 2020

Copy link
Copy Markdown
Contributor

AlwaysBreakBeforeMultilineStrings: false will make the following
change, causing howls. Setting it true didn't make any difference
on other parts of code (it won't try to recombine multi-line strings).

-const std::unordered_map<uint, std::string> BLAH_BLAH_MAP(
-    { { ITEM_UNO, "Lorem ipsum dolor sit amet, consectetur adipiscing" },
-      { ITEM_DOS_SUPER_DUPER_YUCK,
-        "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium "
-        "doloremque" },
- [...]
+const std::unordered_map<uint, std::string> BLAH_BLAH_MAP({ { ITEM_UNO, "Lorem ipsum dolor sit amet, consectetur "
+                                                                         "adipiscing" },
+                                                             { ITEM_DOS_SUPER_DUPER_YUCK, "Sed ut perspiciatis "
+                                                                                          "unde omnis iste natus "
+                                                                                          "error sit voluptatem "
+                                                                                          "accusantium" },
+ [...]

`AlwaysBreakBeforeMultilineStrings: false` will make the following
change, causing howls.  Setting it `true` didn't make any difference
on other parts of code (it won't try to recombine multi-line strings).

    -const std::unordered_map<uint, std::string> BLAH_BLAH_MAP(
    -    { { ITEM_UNO, "Lorem ipsum dolor sit amet, consectetur adipiscing" },
    -      { ITEM_DOS_SUPER_DUPER_YUCK,
    -        "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium "
    -        "doloremque" },
    - [...]
    +const std::unordered_map<uint, std::string> BLAH_BLAH_MAP({ { ITEM_UNO, "Lorem ipsum dolor sit amet, consectetur "
    +                                                                         "adipiscing" },
    +                                                             { ITEM_DOS_SUPER_DUPER_YUCK, "Sed ut perspiciatis "
    +                                                                                          "unde omnis iste natus "
    +                                                                                          "error sit voluptatem "
    +                                                                                          "accusantium" },
    + [...]
@davetcoleman

Copy link
Copy Markdown
Member

@rhaschke do you think this change makes sense for ROS 1 clang format?

@rhaschke

Copy link
Copy Markdown

The key issue here is that the false setting results in splitting a long string into many short lines if (and only if) the string starts at a high column number. On the other hand, always splitting will result in undesired formatting if the long string starts in a low column:

true:                                  false:
aaaa =                         vs.     aaaa = "bbbb"
    "bbbb"                                    "cccc";
    "cccc";

So, both approaches have their pros and cons. I don't really care.

@davetcoleman
davetcoleman merged commit 75a84b0 into PickNikRobotics:master Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants