diff --git a/src/hb-common.cc b/src/hb-common.cc index 20993c6ad..a886474ef 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -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; } diff --git a/src/hb-common.h b/src/hb-common.h index a30587a08..f0fe63a73 100644 --- a/src/hb-common.h +++ b/src/hb-common.h @@ -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); diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc index 5d471159b..9fb6f107a 100644 --- a/src/hb-ot-tag.cc +++ b/src/hb-ot-tag.cc @@ -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); diff --git a/src/hb-shape.cc b/src/hb-shape.cc index fccb81e3b..8855eaf4b 100644 --- a/src/hb-shape.cc +++ b/src/hb-shape.cc @@ -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 (); } diff --git a/test/test-common.c b/test/test-common.c index c1e3175b5..a75138c02 100644 --- a/test/test-common.c +++ b/test/test-common.c @@ -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