Code

GIT 1.5.6-rc3
[git.git] / strbuf.c
index b9b194b3200e950cfdb3c696d92ece0657e9d344..4aed75265e945d7b8dfafb36913006376768b4d3 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,5 +1,14 @@
 #include "cache.h"
 
+int prefixcmp(const char *str, const char *prefix)
+{
+       for (; ; str++, prefix++)
+               if (!*prefix)
+                       return 0;
+               else if (*str != *prefix)
+                       return (unsigned char)*prefix - (unsigned char)*str;
+}
+
 /*
  * Used as the default ->buf value, so that people can always assume
  * buf is non NULL and ->buf is NUL terminated even for a freshly
@@ -137,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);
@@ -149,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, '%');
        }
 }