From 9b864e730bda0e028a85387fa568429724582f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 23 Nov 2008 00:09:30 +0100 Subject: add strbuf_expand_dict_cb(), a helper for simple cases The new callback function strbuf_expand_dict_cb() can be used together with strbuf_expand() if there is only a small number of placeholders for static replacement texts. It expects its dictionary as an array of placeholder+value pairs as context parameter, terminated by an entry with the placeholder member set to NULL. The new helper is intended to aid converting the remaining calls of interpolate(). strbuf_expand() is smaller, more flexible and can be used to go faster than interpolate(), so it should replace the latter. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- strbuf.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index eba7ba423..b1670d994 100644 --- a/strbuf.h +++ b/strbuf.h @@ -111,6 +111,11 @@ extern void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len); typedef size_t (*expand_fn_t) (struct strbuf *sb, const char *placeholder, void *context); extern void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn, void *context); +struct strbuf_expand_dict_entry { + const char *placeholder; + const char *value; +}; +extern size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder, void *context); __attribute__((format(printf,2,3))) extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...); -- cgit v1.2.1