[fcformat] Support indexing simple tags

The format '%{family[0]}' will only output the first value for element family.
This commit is contained in:
Behdad Esfahbod 2009-02-11 23:44:36 -05:00
parent d04a750764
commit 9c83a8376f
3 changed files with 45 additions and 5 deletions

View File

@ -39,9 +39,8 @@
*/ */
/* fc-match needs '<unknown filename>', etc handling, as well as printing /* fc-match needs '<unknown filename>', etc handling. */
* printing first value only. */ #define FCMATCH_FORMAT "%{file|basename}: \"%{family[0]}\" \"%{style[0]}\""
#define FCMATCH_FORMAT "%{file|basename}: \"%{family}\" \"%{style}\""
#define FCLIST_FORMAT "%{?file{%{file}: }}%{=unparse}" #define FCLIST_FORMAT "%{?file{%{file}: }}%{=unparse}"
@ -543,6 +542,7 @@ interpret_simple (FcFormatContext *c,
FcPatternElt *e; FcPatternElt *e;
FcBool add_colon = FcFalse; FcBool add_colon = FcFalse;
FcBool add_elt_name = FcFalse; FcBool add_elt_name = FcFalse;
int idx;
if (consume_char (c, ':')) if (consume_char (c, ':'))
add_colon = FcTrue; add_colon = FcTrue;
@ -550,6 +550,19 @@ interpret_simple (FcFormatContext *c,
if (!read_word (c)) if (!read_word (c))
return FcFalse; return FcFalse;
idx = -1;
if (consume_char (c, '['))
{
idx = strtol ((const char *) c->format, (char **) &c->format, 10);
if (idx < 0)
{
message ("expected non-negative number at %d",
c->format-1 - c->format_orig + 1);
return FcFalse;
}
expect_char (c, ']');
}
if (consume_char (c, '=')) if (consume_char (c, '='))
add_elt_name = FcTrue; add_elt_name = FcTrue;
@ -568,7 +581,29 @@ interpret_simple (FcFormatContext *c,
} }
l = FcPatternEltValues(e); l = FcPatternEltValues(e);
FcNameUnparseValueList (buf, l, '\0');
if (idx != -1)
{
while (l && idx > 0)
{
l = FcValueListNext(l);
idx--;
}
if (l && idx == 0)
{
if (!FcNameUnparseValue (buf, &l->value, '\0'))
return FcFalse;
}
else goto notfound;
}
else
{
FcNameUnparseValueList (buf, l, '\0');
}
}
else
notfound:
{
} }
return FcTrue; return FcTrue;

View File

@ -645,6 +645,11 @@ FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
FcPrivate FcCharSet * FcPrivate FcCharSet *
FcNameParseCharSet (FcChar8 *string); FcNameParseCharSet (FcChar8 *string);
FcPrivate FcBool
FcNameUnparseValue (FcStrBuf *buf,
FcValue *v0,
FcChar8 *escape);
FcPrivate FcBool FcPrivate FcBool
FcNameUnparseValueList (FcStrBuf *buf, FcNameUnparseValueList (FcStrBuf *buf,
FcValueListPtr v, FcValueListPtr v,

View File

@ -783,7 +783,7 @@ FcNameUnparseString (FcStrBuf *buf,
return FcTrue; return FcTrue;
} }
static FcBool FcBool
FcNameUnparseValue (FcStrBuf *buf, FcNameUnparseValue (FcStrBuf *buf,
FcValue *v0, FcValue *v0,
FcChar8 *escape) FcChar8 *escape)