From 44ccb337f10a08bb265b911f86deaf5f3347d967 Mon Sep 17 00:00:00 2001 From: René Scharfe Date: Sat, 17 Jun 2023 22:41:44 +0200 Subject: strbuf: factor out strbuf_expand_step() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- builtin/branch.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'builtin') diff --git a/builtin/branch.c b/builtin/branch.c index e6c2655af6..7c20e049a2 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -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; } -- cgit v1.3-6-g1900