Skip to content

Commit

Permalink
Make tag normalization more conservative: normalize only the bit that…
Browse files Browse the repository at this point in the history
… looks like a language tag
  • Loading branch information
rrthomas committed Sep 24, 2023
1 parent 136fa1f commit 15b8076
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,20 @@ enchant_normalize_dictionary_tag (const char * const dict_tag)
/* strip off en_GB.UTF-8 */
*strchrnul (new_tag, '.') = '\0';

/* turn en-GB into en_GB */
char * needle;
if ((needle = strchr (new_tag, '-')) != NULL)
*needle = '_';

/* everything before first '_' is converted to lower case */
needle = strchrnul (new_tag, '_');
for (gchar *it = new_tag; it != needle; ++it)
/* everything before first '_' or '-' is converted to lower case */
gchar *it = new_tag;
for (; *it != '\0' && *it != '-' && *it != '_'; ++it)
*it = g_ascii_tolower (*it);
/* everything after first '_' is converted to upper case */
for (gchar *it = needle; *it; ++it)
*it = g_ascii_toupper (*it);

/* turn en-GB into en_GB */
if (*it == '-')
*it = '_';

/* first run of alphanumberics after first '_' is converted to upper
case */
if (*it != '\0')
for (++it; g_ascii_isalnum (*it); ++it)
*it = g_ascii_toupper (*it);

return new_tag;
}
Expand Down

0 comments on commit 15b8076

Please sign in to comment.