strbuf: accept a comment string for strbuf_stripspace()
As part of our transition to multi-byte comment characters, let's take a NUL-terminated string pointer for strbuf_stripspace(), rather than a single character. We can continue to support its feature of ignoring comments by accepting a NULL pointer (as opposed to the current behavior of a NUL byte). All of the callers have to be adjusted, but they can all just pass comment_line_str (or NULL). Inside the function we detect comments by comparing the first byte of a line to the comment character. We'll adjust that to use starts_with(), which will match multiple bytes (though for now, of course, we still only allow a single byte, so it's academic). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
72a7d5d97f
commit
2982b65690
6
strbuf.c
6
strbuf.c
@ -1001,10 +1001,10 @@ static size_t cleanup(char *line, size_t len)
|
||||
*
|
||||
* If last line does not have a newline at the end, one is added.
|
||||
*
|
||||
* Pass a non-NUL comment_prefix to skip every line starting
|
||||
* Pass a non-NULL comment_prefix to skip every line starting
|
||||
* with it.
|
||||
*/
|
||||
void strbuf_stripspace(struct strbuf *sb, char comment_prefix)
|
||||
void strbuf_stripspace(struct strbuf *sb, const char *comment_prefix)
|
||||
{
|
||||
size_t empties = 0;
|
||||
size_t i, j, len, newlen;
|
||||
@ -1018,7 +1018,7 @@ void strbuf_stripspace(struct strbuf *sb, char comment_prefix)
|
||||
len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
|
||||
|
||||
if (comment_prefix && len &&
|
||||
sb->buf[i] == comment_prefix) {
|
||||
starts_with(sb->buf + i, comment_prefix)) {
|
||||
newlen = 0;
|
||||
continue;
|
||||
}
|
||||
|
Reference in New Issue
Block a user