diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2008-02-14 15:02:18 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2008-02-14 15:02:18 +0200 |
commit | edab017e93cc372966d39badf7da810da26c0b47 (patch) | |
tree | 9d6dcd5688c804b7685016cf7b30a4341105be3b | |
parent | d1fce56d2cdc03006689ac224a4b1f40ecb786a9 (diff) | |
download | rpm-edab017e93cc372966d39badf7da810da26c0b47.tar.gz |
Improve header i18n locale matching
- Get best lang from rpm HEADERI18NTABLE, instead of getting first fuzzy match
(eg: zh_TW matches zh_CN whereas zh_TW entry is available)
Patch from Pascal Rigaux
(transplanted from 184a4fb00470beb450e6feb834954d6336ad15f7)
-rw-r--r-- | rpmdb/header.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/rpmdb/header.c b/rpmdb/header.c index 3f9bd3a49..20e126a71 100644 --- a/rpmdb/header.c +++ b/rpmdb/header.c @@ -1527,7 +1527,7 @@ static int copyEntry(const indexEntry entry, * @param td header i18n table data, NUL terminated * @param l start of locale to match * @param le end of locale to match - * @return 1 on match, 0 on no match + * @return 1 on good match, 2 on weak match, 0 on no match */ static int headerMatchLocale(const char *td, const char *l, const char *le) /*@*/ @@ -1590,7 +1590,7 @@ static int headerMatchLocale(const char *td, const char *l, const char *le) for (fe = l; fe < le && *fe != '_'; fe++) {}; if (fe < le && !strncmp(td, l, (fe - l))) - return 1; + return 2; return 0; } @@ -1623,7 +1623,7 @@ headerFindI18NString(Header h, indexEntry entry) /*@-boundsread@*/ for (l = lang; *l != '\0'; l = le) { const char *td; - char *ed; + char *ed, *ed_weak = NULL; int langNum; while (*l && *l == ':') /* skip leading colons */ @@ -1638,10 +1638,12 @@ headerFindI18NString(Header h, indexEntry entry) langNum < entry->info.count; langNum++, td += strlen(td) + 1, ed += strlen(ed) + 1) { - if (headerMatchLocale(td, l, le)) - return ed; + int match = headerMatchLocale(td, l, le); + if (match == 1) return ed; + else if (match == 2) ed_weak = ed; } + if (ed_weak) return ed_weak; } /*@=boundsread@*/ |