summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2014-06-02 14:49:30 -0600
committerKarl Williamson <khw@cpan.org>2014-06-05 12:23:02 -0600
commitd6ded95025185cb1ec8ca3ba5879cab881d8b180 (patch)
tree2d5d8e027167706f5a25f1456331ce3e189f1232 /locale.c
parente9efacb9548c04c657ed5e5320168a87934aec52 (diff)
downloadperl-d6ded95025185cb1ec8ca3ba5879cab881d8b180.tar.gz
Add parameters to "use locale"
This commit allows one to specify to enable locale-awareness for only a specified subset of the locale categories. Thus you could make a section of code LC_MESSAGES aware, with no locale-awareness for the other categories.
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/locale.c b/locale.c
index 929a249a81..adaa294952 100644
--- a/locale.c
+++ b/locale.c
@@ -1385,6 +1385,27 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category)
#endif
+
+bool
+Perl__is_in_locale_category(pTHX_ const bool compiling, const int category)
+{
+ /* Internal function which returns if we are in the scope of a pragma that
+ * enables the locale category 'category'. 'compiling' should indicate if
+ * this is during the compilation phase (TRUE) or not (FALSE). */
+
+ const COP * const cop = (compiling) ? &PL_compiling : PL_curcop;
+
+ SV *categories = cop_hints_fetch_pvs(cop, "locale", 0);
+ if (! categories || categories == &PL_sv_placeholder) {
+ return FALSE;
+ }
+
+ /* The pseudo-category 'not_characters' is -1, so just add 1 to each to get
+ * a valid unsigned */
+ assert(category >= -1);
+ return cBOOL(SvUV(categories) & (1U << (category + 1)));
+}
+
/*
* Local variables:
* c-indentation-style: bsd