]> git.ipfire.org Git - thirdparty/git.git/blobdiff - strbuf.c
add strbuf_expand_dict_cb(), a helper for simple cases
[thirdparty/git.git] / strbuf.c
index 720737d856b694bc5239f0c18af372959c99e744..13be67e4d3e38472adbff019a34e3f5ce9621dd7 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -237,6 +237,22 @@ void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn,
        }
 }
 
+size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder,
+               void *context)
+{
+       struct strbuf_expand_dict_entry *e = context;
+       size_t len;
+
+       for (; e->placeholder && (len = strlen(e->placeholder)); e++) {
+               if (!strncmp(placeholder, e->placeholder, len)) {
+                       if (e->value)
+                               strbuf_addstr(sb, e->value);
+                       return len;
+               }
+       }
+       return 0;
+}
+
 size_t strbuf_fread(struct strbuf *sb, size_t size, FILE *f)
 {
        size_t res;