Subject: | Optional locale argument for upper ... |
The attached patch is meant as a discussion base for introducing an optional locale parameter for the upper (and if it gets accepted, also for lower, ucfirst, lcfirst etc.) filter.
Regards,
Slaven
#
#
# To apply this patch:
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'applypatch' program with this patch file as input.
#
# If you do not have 'applypatch', it is part of the 'makepatch' package
# that you can fetch from the Comprehensive Perl Archive Network:
# http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz
# In the above URL, 'x' should be 2 or higher.
#
# To apply this patch without the use of 'applypatch':
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'patch' program with this file as input.
#
#### End of Preamble ####
#### Patch data follows ####
diff -up '/usr/local/dist/cpan/build/Template-Toolkit-2.13/lib/Template/Filters.pm' 'lib/Template/Filters.pm'
Index: ./lib/Template/Filters.pm
Prereq: 2.77
--- ./lib/Template/Filters.pm Fri Jan 30 19:37:50 2004
+++ ./lib/Template/Filters.pm Wed Mar 17 12:25:51 2004
@@ -52,7 +52,7 @@ $FILTERS = {
'html_para_break' => \&html_para_break,
'html_line_break' => \&html_line_break,
'uri' => \&uri_filter,
- 'upper' => sub { uc $_[0] },
+ 'upper' => [ \&upper_filter_factory, 1 ],
'lower' => sub { lc $_[0] },
'ucfirst' => sub { ucfirst $_[0] },
'lcfirst' => sub { lcfirst $_[0] },
@@ -84,6 +84,26 @@ $FILTERS = {
$PLUGIN_FILTER = 'Template::Plugin::Filter';
+sub upper_filter_factory {
+ my ($context, $locale) = @_;
+ if (!defined $locale) {
+ return sub { uc $_[0] }
+ } else {
+ return sub {
+ my $text = shift;
+ $locale = $locale; # make it into this closure...
+ my $code = <<EOF;
+use locale;
+use POSIX qw(setlocale LC_CTYPE);
+setlocale(LC_CTYPE, \$locale);
+uc \$text;
+EOF
+ eval $code;
+ };
+ }
+}
+
+
#========================================================================
# -- PUBLIC METHODS --
#========================================================================
diff -up '/usr/local/dist/cpan/build/Template-Toolkit-2.13/t/filter.t' 't/filter.t'
Index: ./t/filter.t
Prereq: 2.20
--- ./t/filter.t Tue Apr 29 14:49:43 2003
+++ ./t/filter.t Wed Mar 17 12:31:19 2004
@@ -915,4 +915,20 @@ Foobar
-- expect --
fOOBAR
+-- test --
+[% FILTER upper('en_GB.iso885915') -%]
+änglisch
+[% END %]
+-- expect --
+ÃNGLISCH
+
+-- test --
+[% 'änglisch' | upper('en_GB.iso885915') %]
+-- expect --
+ÃNGLISCH
+
+-- test --
+[% 'änglisch' | upper('C') %]
+-- expect --
+äNGLISCH
#### End of Patch data ####
#### ApplyPatch data follows ####
# Data version : 1.0
# Date generated : Wed Mar 17 12:31:38 2004
# Generated by : makepatch 2.00_07*
# Recurse directories : Yes
# Excluded files : (\A|/).*\~\Z
# (\A|/).*\.a\Z
# (\A|/).*\.bak\Z
# (\A|/).*\.BAK\Z
# (\A|/).*\.elc\Z
# (\A|/).*\.exe\Z
# (\A|/).*\.gz\Z
# (\A|/).*\.ln\Z
# (\A|/).*\.o\Z
# (\A|/).*\.obj\Z
# (\A|/).*\.olb\Z
# (\A|/).*\.old\Z
# (\A|/).*\.orig\Z
# (\A|/).*\.rej\Z
# (\A|/).*\.so\Z
# (\A|/).*\.Z\Z
# (\A|/)\.del\-.*\Z
# (\A|/)\.make\.state\Z
# (\A|/)\.nse_depinfo\Z
# (\A|/)core\Z
# (\A|/)tags\Z
# (\A|/)TAGS\Z
# p 'lib/Template/Filters.pm' 44592 1079522751 0100644
# p 't/filter.t' 17279 1079523079 0100755
#### End of ApplyPatch data ####
#### End of Patch kit [created: Wed Mar 17 12:31:38 2004] ####
#### Patch checksum: 102 3199 8567 ####
#### Checksum: 120 3823 60101 ####