strbuf: factor out strbuf_expand_step()
Extract the part of strbuf_expand that finds the next placeholder into a new function. It allows to build parsers without callback functions and the overhead imposed by them. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
3c3d0c4242
commit
44ccb337f1
@@ -366,17 +366,8 @@ static const char *quote_literal_for_format(const char *s)
|
||||
static struct strbuf buf = STRBUF_INIT;
|
||||
|
||||
strbuf_reset(&buf);
|
||||
while (*s) {
|
||||
const char *ep = strchrnul(s, '%');
|
||||
if (s < ep)
|
||||
strbuf_add(&buf, s, ep - s);
|
||||
if (*ep == '%') {
|
||||
strbuf_addstr(&buf, "%%");
|
||||
s = ep + 1;
|
||||
} else {
|
||||
s = ep;
|
||||
}
|
||||
}
|
||||
while (strbuf_expand_step(&buf, &s))
|
||||
strbuf_addstr(&buf, "%%");
|
||||
return buf.buf;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user