summaryrefslogtreecommitdiff
path: root/ext/I18N-Langinfo
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2021-02-18 17:26:55 -0700
committerKarl Williamson <khw@cpan.org>2022-08-22 06:52:08 -0600
commitd0826532cb20a8907f8ba1959ef019f57f36cf69 (patch)
treeaf446a922146cb44dffd636abcd473c09ea9d8e1 /ext/I18N-Langinfo
parentfffcb78fe024e52627bb329d34cf0f1d2cf5b4f1 (diff)
downloadperl-d0826532cb20a8907f8ba1959ef019f57f36cf69.tar.gz
Add Perl_langinfo8()
This is like Perl_langinfo() but additionally returns information about the UTF-8ness of the returned string.
Diffstat (limited to 'ext/I18N-Langinfo')
-rw-r--r--ext/I18N-Langinfo/Langinfo.xs64
1 files changed, 4 insertions, 60 deletions
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: