diff options
author | Mattias Andrée <maandree@kth.se> | 2023-01-10 18:59:00 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-01-10 18:59:00 +0100 |
commit | 73e12ac4d3553f05a0337cd8d49d8ec3084a3788 (patch) | |
tree | e129ebee5e03fbe8a2eb321fe6d809d7aba24e2c /libfonts_do_decoded_font_descriptions_match.c | |
parent | m + implement libfonts_do_{decoded_,}font_descriptions_match (diff) | |
download | libfonts-73e12ac4d3553f05a0337cd8d49d8ec3084a3788.tar.gz libfonts-73e12ac4d3553f05a0337cd8d49d8ec3084a3788.tar.bz2 libfonts-73e12ac4d3553f05a0337cd8d49d8ec3084a3788.tar.xz |
libfonts_do_font_descriptions_match: attempt to decode first to handle unnormalized data
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libfonts_do_decoded_font_descriptions_match.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/libfonts_do_decoded_font_descriptions_match.c b/libfonts_do_decoded_font_descriptions_match.c index 69f7cf0..24d3268 100644 --- a/libfonts_do_decoded_font_descriptions_match.c +++ b/libfonts_do_decoded_font_descriptions_match.c @@ -41,12 +41,38 @@ equal(const char *desc, const char *spec) return desc[i] == spec[i]; } +static int +many_equal(const char *desc, const char *spec) +{ + if (!spec) + return !desc; + if (!desc) + return 0; + + while (*spec && *desc) { + if (spec[0] == '*' && (!spec[1] || spec[1] == '-')) { + spec++; + while (*desc && *desc != '-') + desc++; + } else { + while (*spec && *desc && *spec != '-' && *desc != '-') { + if (*spec != *desc && *spec != '?') + return 0; + } + } + if (*spec != *desc || (*spec && *spec != '-')) + return 0; + } + + return *spec == *desc; +} + int libfonts_do_decoded_font_descriptions_match(const struct libfonts_font_description *desc, const struct libfonts_font_description *spec) { if (desc->private_font_name || spec->private_font_name) - return libfonts_do_font_descriptions_match(desc->private_font_name, spec->private_font_name); + return many_equal(desc->private_font_name, spec->private_font_name); #define X(F)\ if (!equal(desc->F, spec->F))\ @@ -54,7 +80,7 @@ libfonts_do_decoded_font_descriptions_match(const struct libfonts_font_descripti LIST_ALL_FIELDS(X, ;); #undef X - return libfonts_do_font_descriptions_match(desc->unrecognised_fields, spec->unrecognised_fields); + return many_equal(desc->unrecognised_fields, spec->unrecognised_fields); } |