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 --- strbuf.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index 3dfeadb44c..a189f12b84 100644 --- a/strbuf.h +++ b/strbuf.h @@ -371,6 +371,14 @@ size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder, void *context); +/** + * If the string pointed to by `formatp` contains a percent sign ("%"), + * advance it to point to the character following the next one and + * return 1, otherwise return 0. Append the substring before that + * percent sign to `sb`, or the whole string if there is none. + */ +int strbuf_expand_step(struct strbuf *sb, const char **formatp); + /** * Append the contents of one strbuf to another, quoting any * percent signs ("%") into double-percents ("%%") in the -- cgit v1.3-5-g9baa