]> asedeno.scripts.mit.edu Git - git.git/blobdiff - strbuf.c
Make some strbuf_*() struct strbuf arguments const.
[git.git] / strbuf.c
index 5efcfc8860a82766b53a0d579fbdd0844d0f9b62..7767170db3201dc34c43eaa100c84b6c70a8e568 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -67,7 +67,7 @@ void strbuf_rtrim(struct strbuf *sb)
        sb->buf[sb->len] = '\0';
 }
 
-int strbuf_cmp(struct strbuf *a, struct strbuf *b)
+int strbuf_cmp(const struct strbuf *a, const struct strbuf *b)
 {
        int cmp;
        if (a->len < b->len) {
@@ -146,11 +146,12 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
        strbuf_setlen(sb, sb->len + len);
 }
 
-void strbuf_expand(struct strbuf *sb, const char *format,
-                   const char **placeholders, expand_fn_t fn, void *context)
+void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn,
+                  void *context)
 {
        for (;;) {
-               const char *percent, **p;
+               const char *percent;
+               size_t consumed;
 
                percent = strchrnul(format, '%');
                strbuf_add(sb, format, percent - format);
@@ -158,14 +159,10 @@ void strbuf_expand(struct strbuf *sb, const char *format,
                        break;
                format = percent + 1;
 
-               for (p = placeholders; *p; p++) {
-                       if (!prefixcmp(format, *p))
-                               break;
-               }
-               if (*p) {
-                       fn(sb, *p, context);
-                       format += strlen(*p);
-               } else
+               consumed = fn(sb, format, context);
+               if (consumed)
+                       format += consumed;
+               else
                        strbuf_addch(sb, '%');
        }
 }