From d0826532cb20a8907f8ba1959ef019f57f36cf69 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Thu, 18 Feb 2021 17:26:55 -0700 Subject: Add Perl_langinfo8() This is like Perl_langinfo() but additionally returns information about the UTF-8ness of the returned string. --- ext/I18N-Langinfo/Langinfo.xs | 64 +++---------------------------------------- 1 file changed, 4 insertions(+), 60 deletions(-) (limited to 'ext/I18N-Langinfo') diff --git a/ext/I18N-Langinfo/Langinfo.xs b/ext/I18N-Langinfo/Langinfo.xs index 904b424b19..3b05e9f791 100644 --- a/ext/I18N-Langinfo/Langinfo.xs +++ b/ext/I18N-Langinfo/Langinfo.xs @@ -25,8 +25,8 @@ SV* langinfo(code) int code PREINIT: - const char * value; - STRLEN len; + const char * value; + utf8ness_t is_utf8; PROTOTYPE: _ CODE: #ifdef HAS_NL_LANGINFO @@ -36,64 +36,8 @@ langinfo(code) } else #endif { - value = Perl_langinfo(code); - len = strlen(value); - RETVAL = newSVpvn(Perl_langinfo(code), len); - - /* Now see if the UTF-8 flag should be turned on */ -#ifdef USE_LOCALE_CTYPE /* No utf8 strings if not using LC_CTYPE */ - - /* If 'value' is ASCII or not legal UTF-8, the flag doesn't get - * turned on, so skip the followin code */ - if (is_utf8_non_invariant_string((U8 *) value, len)) { - int category; - - /* Check if the locale is a UTF-8 one. The returns from - * Perl_langinfo() are in different locale categories, so check the - * category corresponding to this item */ - switch (code) { - - /* This should always return ASCII, so we could instead - * legitimately panic here, but soldier on */ - case CODESET: - category = LC_CTYPE; - break; - - case RADIXCHAR: - case THOUSEP: -# ifdef USE_LOCALE_NUMERIC - category = LC_NUMERIC; -# else - /* Not ideal, but the best we can do on such a platform */ - category = LC_CTYPE; -# endif - break; - - case CRNCYSTR: -# ifdef USE_LOCALE_MONETARY - category = LC_MONETARY; -# else - category = LC_CTYPE; -# endif - break; - - default: -# ifdef USE_LOCALE_TIME - category = LC_TIME; -# else - category = LC_CTYPE; -# endif - break; - } - - /* Here the return is legal UTF-8. Turn on that flag if the - * locale is UTF-8. (Otherwise, could just be a coincidence.) - * */ - if (_is_cur_LC_category_utf8(category)) { - SvUTF8_on(RETVAL); - } - } -#endif /* USE_LOCALE_CTYPE */ + value = Perl_langinfo8(code, &is_utf8); + RETVAL = newSVpvn_utf8(value, strlen(value), is_utf8 == UTF8NESS_YES); } OUTPUT: -- cgit v1.2.1