strbuf: accept a comment string for strbuf_add_commented_lines()

As part of our transition to multi-byte comment characters, let's take a
NUL-terminated string pointer for strbuf_add_commented_lines() rather
than a single character.

All of the callers have to be adjusted; most can just pass
comment_line_str rather than comment_line_char.

And now our "cheat" in strbuf_commented_addf() can go away, as we can
take the full string from it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King
2024-03-12 05:17:32 -04:00
committed by Junio C Hamano
parent 3a35d96284
commit a1bb146aaf
8 changed files with 21 additions and 31 deletions

View File

@ -359,13 +359,9 @@ static void add_lines(struct strbuf *out,
}
void strbuf_add_commented_lines(struct strbuf *out, const char *buf,
size_t size, char comment_prefix)
size_t size, const char *comment_prefix)
{
char prefix[2];
prefix[0] = comment_prefix;
prefix[1] = '\0';
add_lines(out, prefix, buf, size, 1);
add_lines(out, comment_prefix, buf, size, 1);
}
void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
@ -379,13 +375,7 @@ void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
strbuf_vaddf(&buf, fmt, params);
va_end(params);
/*
* TODO Our commented_lines helper does not yet understand
* comment strings. But since we know that the strings are
* always single-char, we can cheat for the moment, and
* fix this later.
*/
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_prefix[0]);
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_prefix);
if (incomplete_line)
sb->buf[--sb->len] = '\0';