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 | |
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 | ||||
-rw-r--r-- | libfonts_do_font_descriptions_match.c | 26 |
2 files changed, 40 insertions, 16 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); } diff --git a/libfonts_do_font_descriptions_match.c b/libfonts_do_font_descriptions_match.c index 1bf6069..9936856 100644 --- a/libfonts_do_font_descriptions_match.c +++ b/libfonts_do_font_descriptions_match.c @@ -6,27 +6,25 @@ int libfonts_do_font_descriptions_match(const char *desc, const char *spec) { + struct libfonts_font_description desc_decoded; + struct libfonts_font_description spec_decoded; + 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; + if (strlen(desc) > 255 || strlen(spec) > 255) { + fallback: + desc_decoded.private_font_name = desc; + spec_decoded.private_font_name = spec; + } else { + if (libfonts_decode_font_description(&desc_decoded, desc) || + libfonts_decode_font_description(&spec_decoded, spec)) + goto fallback; } - return *spec == *desc; + return libfonts_do_decoded_font_descriptions_match(&desc_decoded, &spec_decoded); } |