Skip to content
Snippets Groups Projects
Commit d9347452 authored by Lyndon Brown's avatar Lyndon Brown Committed by Jean-Baptiste Kempf
Browse files

iso639: replace the name-inclusive search algorithm

...with one that searches the names of all the records, then the codes,
rather than all attributes of one record, then the next.

(it is not necessarily the final form of this new algorithm, with a
further tweak to come in the next commit).

this alternate implementation, is just a simple extension of the "normal"
(code-only) search algorithm, adding an extra conditional table attribute
search, rather than having an entirely different algorithm for
name-inclusive searches (which was copied from the old hack this replaced).

also, under this new algorithm, ISO-639-1 codes are only compared when
len==2, and similarly ISO-639-2 codes are only compared when len==3,
saving wasted comparison effort in exchange for some possible more looping.

note that name-inclusive searches are only performed by dvdnav, bluray, and
esout, and only the first two are relevant with respect to considering any
difference in results, since esout assumes 2/3 char language strings are
iso-639 codes and thus does not perform a name-inclusive search for them (at
the expense of not being able to reach the three letter name records by
name). for dvdnav and bluray, this concerns recognising any user specified
option values indicating "preferred language" per
fc4005c1.

-- result differences --

the results given happen to be identical to that of the previous algorithm,
both with the current data set, and the updated one in MR 146 ([1]).

noting that the table is updated from the data from glibc, maintaining the
same order, it should be understood that the results would only be
different to the previous algorithm if the table ever had an entry added
with a three/two character name that matches (case insensitively) a code
from an entry earlier in the table, in which case this new entry would be
the match rather than the earlier entry. (name match now always wins
rather than first matching record in the list).

[1]: !146
parent 58ef2327
No related branches found
No related tags found
1 merge request!167iso639: lookup fixes and improvements
......@@ -46,12 +46,13 @@ extern "C" {
* ISO-639-2B (English) code attributes, falling back to the ISO-639-2T (native)
* code attributes if no match. (Case insensitive).
*
* If `any_field` is set to `true`, then an alternate search is performed of all
* properties including language name (case-insensitive).
* If `try_name` is set to `true`, then a (case-insensitive) search of language
* names will be performed first, falling back upon a code search if no name
* matched.
*
* @return A pointer to the matching record, or NULL if no match.
*/
VLC_API const iso639_lang_t * vlc_find_iso639( const char *code, bool any_field );
VLC_API const iso639_lang_t * vlc_find_iso639( const char *code, bool try_name );
#if defined( __cplusplus )
}
......
......@@ -73,28 +73,28 @@ static const iso639_lang_t * GetLang_2B( const char * psz_code )
return NULL;
}
static const iso639_lang_t * GetLang_AnyField( const char * psz_lang )
static const iso639_lang_t * GetLang_name( const char * psz_lang )
{
const iso639_lang_t *p_lang;
for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
{
if( !strcasecmp( p_lang->psz_eng_name, psz_lang ) ||
!strcasecmp( p_lang->psz_iso639_1, psz_lang ) ||
!strcasecmp( p_lang->psz_iso639_2T, psz_lang ) ||
!strcasecmp( p_lang->psz_iso639_2B, psz_lang ) )
if( !strcasecmp( p_lang->psz_eng_name, psz_lang ) )
return p_lang;
}
return NULL;
}
const iso639_lang_t * vlc_find_iso639( const char *code, bool any_field )
const iso639_lang_t * vlc_find_iso639( const char *code, bool try_name )
{
const iso639_lang_t *result = NULL;
size_t len = strlen(code);
if (any_field)
return (len == 0) ? NULL : GetLang_AnyField(code);
if (try_name && len != 0)
{
result = GetLang_name(code);
if (result)
return result;
}
if (len == 2)
result = GetLang_1(code);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment