X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=strbuf.c;h=4aed75265e945d7b8dfafb36913006376768b4d3;hb=f9d800e2074a60a009e7c670e396a379d8c46cc5;hp=b9b194b3200e950cfdb3c696d92ece0657e9d344;hpb=c477553b2f4f621216b25800e121af52e0750087;p=git.git diff --git a/strbuf.c b/strbuf.c index b9b194b32..4aed75265 100644 --- 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, '%'); } }