Skip to content

Commit

Permalink
Fix align of strings with preproc. concatenations
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnauBigas committed Jun 30, 2022
1 parent 6105704 commit 9e59c77
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/indent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3686,11 +3686,26 @@ void indent_text()
&& options::indent_align_string())
{
log_rule_B("indent_align_string");
const int tmp = (xml_indent != 0) ? xml_indent : prev->column;
int indent;

if (xml_indent != 0)
{
indent = xml_indent;
}
else
{
Chunk *tmp = prev;

while ( tmp->prev
&& (tmp->prev->Is(CT_WORD) || tmp->prev->Is(CT_STRING)))
{
tmp = tmp->prev;
}
indent = tmp->column;
}
LOG_FMT(LINDENT, "%s(%d): orig_line is %zu, String => %d\n",
__func__, __LINE__, pc->orig_line, tmp);
reindent_line(pc, tmp);
__func__, __LINE__, pc->orig_line, indent);
reindent_line(pc, indent);
}
else if (pc->IsComment())
{
Expand Down
3 changes: 3 additions & 0 deletions tests/expected/c/02201-align-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ void foo(void)

fprintf(stderr, "Format string: %s", "This is the first line\n"
"And this is the second.\n");

fprintf(stderr, "Format string: %s", "This is the first line\n" __FILE__ "\n"
"And this is the second.\n");
}

3 changes: 3 additions & 0 deletions tests/input/c/align-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ void foo(void)

fprintf(stderr, "Format string: %s", "This is the first line\n"
"And this is the second.\n");

fprintf(stderr, "Format string: %s", "This is the first line\n" __FILE__ "\n"
"And this is the second.\n");
}

1 comment on commit 9e59c77

@gmaurel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the bug fix

Please sign in to comment.