From 85fd3b72af943e8753e0f28ca6963f11b522adcf Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 15 Feb 2017 09:44:57 -0500 Subject: [PATCH] More support for uiAttributeLanguage. --- common/attrlist.c | 29 +++++++++++++++++++++++++++++ ui_attrstr.h | 1 + 2 files changed, 30 insertions(+) diff --git a/common/attrlist.c b/common/attrlist.c index 746b1e76..3bf8caff 100644 --- a/common/attrlist.c +++ b/common/attrlist.c @@ -291,6 +291,32 @@ static int boolsEqual(struct attr *attr, uiAttributeSpec *spec) return attr->spec.Value != 0 && spec->Value != 0; } +// BCP 47 is ASCII-only +static int asciiStringsEqualCaseFold(const char *a, const char *b) +{ + char c, d; + + for (;;) { + if (*a == *b) { + if (*a == '\0') + return 1; + a++; + b++; + continue; + } + c = *a; + if (c >= 'A' && c <= 'Z') + c += 'a' - 'A'; + d = *b; + if (d >= 'A' && d <= 'Z') + d += 'a' - 'A'; + if (c != d) + return 0; + a++; + b++; + } +} + static int specsIdentical(struct attr *attr, uiAttributeSpec *spec) { if (attr->spec.Type != spec->Type) @@ -298,6 +324,7 @@ static int specsIdentical(struct attr *attr, uiAttributeSpec *spec) switch (attr->spec.Type) { case uiAttributeFamily: // TODO should we start copying these strings? + // TODO should this be case-insensitive? return strcmp((char *) (attr->spec.Value), (char *) (spec->Value)) == 0; case uiAttributeSize: // TODO use a closest match? @@ -317,6 +344,8 @@ static int specsIdentical(struct attr *attr, uiAttributeSpec *spec) attr->spec.A == spec->A; case uiAttributeVerticalForms: return boolsEqual(attr, spec); + case uiAttributeLanguage: + return asciiStringsEqualCaseFold((char *) (attr->spec.Value), (char *) (spec->Value)); // TODO } // handles the rest diff --git a/ui_attrstr.h b/ui_attrstr.h index 8707a375..fac03b0f 100644 --- a/ui_attrstr.h +++ b/ui_attrstr.h @@ -39,6 +39,7 @@ _UI_ENUM(uiAttribute) { // TODO fallbacks (pango: enable or disable) // TODO document that this will also enable language-specific font features (TODO on DirectWrite too?) + // TODO document that this should be strict BCP 47 form (A-Z, a-z, 0-9, and -) for maximum compatibility uiAttributeLanguage, // BCP 47 string #if 0