X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=src%2Ffcformat.c;h=6a463fdb3eb4bd5aa410b01973f4f4b4fbce2b12;hb=b6a23028beb3b99022599344ebd8511c12dc7fd0;hp=238f8d2d93afaf98f54dd7c331faa2e46662f852;hpb=dccbbe83eff54097c55fdc560810cdc56b679a60;p=fontconfig.git diff --git a/src/fcformat.c b/src/fcformat.c index 238f8d2..6a463fd 100644 --- a/src/fcformat.c +++ b/src/fcformat.c @@ -1,5 +1,5 @@ /* - * Copyright © 2008 Red Hat, Inc. + * Copyright © 2008,2009 Red Hat, Inc. * * Red Hat Author(s): Behdad Esfahbod * @@ -31,7 +31,6 @@ /* * Some ideas for future syntax extensions: * - * - number of values for element using '%{#elt}' * - allow indexing subexprs using '%{[idx]elt1,elt2{subexpr}}' * - allow indexing simple tags using '%{elt[idx]}' * - conditional/filtering/deletion on binding (using '(w)'/'(s)' notation) @@ -260,45 +259,6 @@ maybe_skip_subexpr (FcFormatContext *c) FcTrue; } -static FcBool -interpret_simple (FcFormatContext *c, - FcPattern *pat, - FcStrBuf *buf) -{ - FcPatternElt *e; - FcBool add_colon = FcFalse; - FcBool add_elt_name = FcFalse; - - if (consume_char (c, ':')) - add_colon = FcTrue; - - if (!read_word (c)) - return FcFalse; - - if (consume_char (c, '=')) - add_elt_name = FcTrue; - - e = FcPatternObjectFindElt (pat, - FcObjectFromName ((const char *) c->word)); - if (e) - { - FcValueListPtr l; - - if (add_colon) - FcStrBufChar (buf, ':'); - if (add_elt_name) - { - FcStrBufString (buf, c->word); - FcStrBufChar (buf, '='); - } - - l = FcPatternEltValues(e); - FcNameUnparseValueList (buf, l, '\0'); - } - - return FcTrue; -} - static FcBool interpret_filter (FcFormatContext *c, FcPattern *pat, @@ -415,6 +375,79 @@ interpret_cond (FcFormatContext *c, return FcTrue; } +static FcBool +interpret_count (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf) +{ + int count; + FcPatternElt *e; + FcChar8 buf_static[64]; + + if (!expect_char (c, '#')) + return FcFalse; + + if (!read_word (c)) + return FcFalse; + + count = 0; + e = FcPatternObjectFindElt (pat, + FcObjectFromName ((const char *) c->word)); + if (e) + { + FcValueListPtr l; + count++; + for (l = FcPatternEltValues(e); + l->next; + l = l->next) + count++; + } + + snprintf (buf_static, sizeof (buf_static), "%d", count); + FcStrBufString (buf, buf_static); + + return FcTrue; +} + +static FcBool +interpret_simple (FcFormatContext *c, + FcPattern *pat, + FcStrBuf *buf) +{ + FcPatternElt *e; + FcBool add_colon = FcFalse; + FcBool add_elt_name = FcFalse; + + if (consume_char (c, ':')) + add_colon = FcTrue; + + if (!read_word (c)) + return FcFalse; + + if (consume_char (c, '=')) + add_elt_name = FcTrue; + + e = FcPatternObjectFindElt (pat, + FcObjectFromName ((const char *) c->word)); + if (e) + { + FcValueListPtr l; + + if (add_colon) + FcStrBufChar (buf, ':'); + if (add_elt_name) + { + FcStrBufString (buf, c->word); + FcStrBufChar (buf, '='); + } + + l = FcPatternEltValues(e); + FcNameUnparseValueList (buf, l, '\0'); + } + + return FcTrue; +} + static FcChar8 * cescape (const FcChar8 *str) { @@ -593,6 +626,7 @@ interpret_percent (FcFormatContext *c, case '+': ret = interpret_filter (c, pat, buf); break; case '-': ret = interpret_delete (c, pat, buf); break; case '?': ret = interpret_cond (c, pat, buf); break; + case '#': ret = interpret_count (c, pat, buf); break; default: ret = interpret_simple (c, pat, buf); break; }