[API] Add HB_LANGUAGE_INVALID

This commit is contained in:
Behdad Esfahbod 2011-05-13 22:55:32 -04:00
parent 40b5c2e86c
commit 1a64f6e19a
5 changed files with 13 additions and 7 deletions

View File

@ -169,16 +169,17 @@ hb_language_t
hb_language_from_string (const char *str) hb_language_from_string (const char *str)
{ {
if (!str || !*str) if (!str || !*str)
return NULL; return HB_LANGUAGE_INVALID;
hb_language_item_t *item = langs.find_or_insert (str, langs_lock); 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 * const char *
hb_language_to_string (hb_language_t language) hb_language_to_string (hb_language_t language)
{ {
/* This is actually NULL-safe! */
return language->s; return language->s;
} }

View File

@ -114,6 +114,8 @@ hb_language_from_string (const char *str);
const char * const char *
hb_language_to_string (hb_language_t language); hb_language_to_string (hb_language_t language);
#define HB_LANGUAGE_INVALID ((hb_language_t) NULL)
hb_language_t hb_language_t
hb_language_get_default (void); hb_language_get_default (void);

View File

@ -610,7 +610,7 @@ hb_ot_tag_from_language (hb_language_t language)
const char *lang_str, *s; const char *lang_str, *s;
const LangTag *lang_tag; const LangTag *lang_tag;
if (language == NULL) if (language == HB_LANGUAGE_INVALID)
return HB_OT_TAG_DEFAULT_LANGUAGE; return HB_OT_TAG_DEFAULT_LANGUAGE;
lang_str = hb_language_to_string (language); lang_str = hb_language_to_string (language);

View File

@ -79,7 +79,7 @@ hb_shape (hb_font_t *font,
} }
/* If language is not set, use default language from locale */ /* 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 */ /* TODO get_default_for_script? using $LANGUAGE */
buffer->props.language = hb_language_get_default (); buffer->props.language = hb_language_get_default ();
} }

View File

@ -156,6 +156,8 @@ test_types_language (void)
hb_language_t fa_ir = hb_language_from_string ("fa-ir"); hb_language_t fa_ir = hb_language_from_string ("fa-ir");
hb_language_t en = hb_language_from_string ("en"); hb_language_t en = hb_language_from_string ("en");
g_assert (HB_LANGUAGE_INVALID == NULL);
g_assert (fa != NULL); g_assert (fa != NULL);
g_assert (fa_IR != NULL); g_assert (fa_IR != NULL);
g_assert (fa_IR == fa_ir); 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 (en == hb_language_from_string ("eN")); g_assert (en == hb_language_from_string ("eN"));
g_assert (NULL == hb_language_from_string (NULL)); g_assert (HB_LANGUAGE_INVALID == hb_language_from_string (NULL));
g_assert (NULL == hb_language_from_string ("")); 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 /* Not sure how to test this better. Setting env vars
* here doesn't sound like the right approach, and I'm * here doesn't sound like the right approach, and I'm
* not sure that it even works. */ * not sure that it even works. */
g_assert (NULL != hb_language_get_default ()); g_assert (HB_LANGUAGE_INVALID != hb_language_get_default ());
} }
int int