return FALSE;
}
-#if defined(USE_LOCALE_CTYPE) && (defined(MB_CUR_MAX) || defined(HAS_NL_LANGINFO) && defined(CODESET))
+#if defined(USE_LOCALE_CTYPE) \
+ && (defined(MB_CUR_MAX) || (defined(HAS_NL_LANGINFO) && defined(CODESET)))
- { /* Next try MB_CUR_MAX or nl_langinfo if available */
+ { /* Next try nl_langinfo or MB_CUR_MAX if available */
char *save_ctype_locale = NULL;
bool is_utf8;
}
/* Here the current LC_CTYPE is set to the locale of the category whose
- * information is desired. This means that MB_CUR_MAX and
- * nl_langinfo() should give the correct results */
+ * information is desired. This means that nl_langinfo() and MB_CUR_MAX
+ * should give the correct results */
-# ifdef MB_CUR_MAX
+# if defined(HAS_NL_LANGINFO) && defined(CODESET)
+ {
+ char *codeset = savepv(nl_langinfo(CODESET));
+ if (codeset && strNE(codeset, "")) {
- /* If we switched LC_CTYPE, switch back */
- if (save_ctype_locale) {
- setlocale(LC_CTYPE, save_ctype_locale);
- Safefree(save_ctype_locale);
+ /* If we switched LC_CTYPE, switch back */
+ if (save_ctype_locale) {
+ setlocale(LC_CTYPE, save_ctype_locale);
+ Safefree(save_ctype_locale);
+ }
+
+ is_utf8 = foldEQ(codeset, STR_WITH_LEN("UTF-8"))
+ || foldEQ(codeset, STR_WITH_LEN("UTF8"));
+
+ Safefree(codeset);
+ Safefree(save_input_locale);
+ return is_utf8;
+ }
}
+# endif
+# ifdef MB_CUR_MAX
+
+ /* Here, either we don't have nl_langinfo, or it didn't return a
+ * codeset. Try MB_CUR_MAX */
+
/* Standard UTF-8 needs at least 4 bytes to represent the maximum
* Unicode code point. Since UTF-8 is the only non-single byte
* encoding we handle, we just say any such encoding is UTF-8, and if
* result */
if (is_utf8) {
wchar_t wc;
+ (void) mbtowc(&wc, NULL, 0); /* Reset any shift state */
if (mbtowc(&wc, HYPHEN_UTF8, strlen(HYPHEN_UTF8))
!= strlen(HYPHEN_UTF8)
|| wc != (wchar_t) 0x2010)
is_utf8 = FALSE;
}
}
-
# endif
- return is_utf8;
-#else
-# if defined(HAS_NL_LANGINFO) && defined(CODESET)
- {
- char *codeset = savepv(nl_langinfo(CODESET));
- if (codeset) {
-
- /* If we switched LC_CTYPE, switch back */
- if (save_ctype_locale) {
- setlocale(LC_CTYPE, save_ctype_locale);
- Safefree(save_ctype_locale);
- }
-
- is_utf8 = foldEQ(codeset, STR_WITH_LEN("UTF-8"))
- || foldEQ(codeset, STR_WITH_LEN("UTF8"));
-
- Safefree(codeset);
- Safefree(save_input_locale);
- return is_utf8;
- }
+ /* If we switched LC_CTYPE, switch back */
+ if (save_ctype_locale) {
+ setlocale(LC_CTYPE, save_ctype_locale);
+ Safefree(save_ctype_locale);
}
-# endif
+ return is_utf8;
# endif
}