[API] Add HB_LANGUAGE_INVALID
This commit is contained in:
parent
40b5c2e86c
commit
1a64f6e19a
|
@ -169,16 +169,17 @@ hb_language_t
|
|||
hb_language_from_string (const char *str)
|
||||
{
|
||||
if (!str || !*str)
|
||||
return NULL;
|
||||
return HB_LANGUAGE_INVALID;
|
||||
|
||||
hb_language_item_t *item = langs.find_or_insert (str, langs_lock);
|
||||
|
||||
return likely (item) ? item->lang : NULL;
|
||||
return likely (item) ? item->lang : HB_LANGUAGE_INVALID;
|
||||
}
|
||||
|
||||
const char *
|
||||
hb_language_to_string (hb_language_t language)
|
||||
{
|
||||
/* This is actually NULL-safe! */
|
||||
return language->s;
|
||||
}
|
||||
|
||||
|
|
|
@ -114,6 +114,8 @@ hb_language_from_string (const char *str);
|
|||
const char *
|
||||
hb_language_to_string (hb_language_t language);
|
||||
|
||||
#define HB_LANGUAGE_INVALID ((hb_language_t) NULL)
|
||||
|
||||
hb_language_t
|
||||
hb_language_get_default (void);
|
||||
|
||||
|
|
|
@ -610,7 +610,7 @@ hb_ot_tag_from_language (hb_language_t language)
|
|||
const char *lang_str, *s;
|
||||
const LangTag *lang_tag;
|
||||
|
||||
if (language == NULL)
|
||||
if (language == HB_LANGUAGE_INVALID)
|
||||
return HB_OT_TAG_DEFAULT_LANGUAGE;
|
||||
|
||||
lang_str = hb_language_to_string (language);
|
||||
|
|
|
@ -79,7 +79,7 @@ hb_shape (hb_font_t *font,
|
|||
}
|
||||
|
||||
/* If language is not set, use default language from locale */
|
||||
if (buffer->props.language == NULL) {
|
||||
if (buffer->props.language == HB_LANGUAGE_INVALID) {
|
||||
/* TODO get_default_for_script? using $LANGUAGE */
|
||||
buffer->props.language = hb_language_get_default ();
|
||||
}
|
||||
|
|
|
@ -156,6 +156,8 @@ test_types_language (void)
|
|||
hb_language_t fa_ir = hb_language_from_string ("fa-ir");
|
||||
hb_language_t en = hb_language_from_string ("en");
|
||||
|
||||
g_assert (HB_LANGUAGE_INVALID == NULL);
|
||||
|
||||
g_assert (fa != NULL);
|
||||
g_assert (fa_IR != NULL);
|
||||
g_assert (fa_IR == fa_ir);
|
||||
|
@ -167,13 +169,14 @@ test_types_language (void)
|
|||
g_assert (en == hb_language_from_string ("en"));
|
||||
g_assert (en == hb_language_from_string ("eN"));
|
||||
|
||||
g_assert (NULL == hb_language_from_string (NULL));
|
||||
g_assert (NULL == hb_language_from_string (""));
|
||||
g_assert (HB_LANGUAGE_INVALID == hb_language_from_string (NULL));
|
||||
g_assert (HB_LANGUAGE_INVALID == hb_language_from_string (""));
|
||||
g_assert (NULL == hb_language_to_string (HB_LANGUAGE_INVALID));
|
||||
|
||||
/* Not sure how to test this better. Setting env vars
|
||||
* here doesn't sound like the right approach, and I'm
|
||||
* not sure that it even works. */
|
||||
g_assert (NULL != hb_language_get_default ());
|
||||
g_assert (HB_LANGUAGE_INVALID != hb_language_get_default ());
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Reference in New Issue