Skip to content

gv.c - add ${^FORCE_UPGRADE} for triggering upgrade by concatenation #20459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions gv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,16 @@ S_gv_magicalize(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len,
if (memEQs(name, len, "\005NCODING"))
goto magicalize;
break;
case '\006':
if (memEQs(name, len, "\006ORCE_UPGRADE")) { /* ${^FORCE_UPGRADE} */
/* empty string which is marked as UTF8 on */
SV *sv= GvSVn(gv);
sv_setpvs(sv,"");
SvUTF8_on(sv);
SvREADONLY_on(sv);
}
break;

case '\007': /* $^GLOBAL_PHASE */
if (memEQs(name, len, "\007LOBAL_PHASE"))
goto ro_magicalize;
Expand Down
9 changes: 8 additions & 1 deletion lib/utf8.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use warnings;

our $hint_bits = 0x00800000;

our $VERSION = '1.24';
our $VERSION = '1.25';
our $AUTOLOAD;

sub import {
Expand Down Expand Up @@ -133,6 +133,13 @@ For example:
$x =~ /ss/i; # matches
my $z = uc($x); # converts to "SS"

As of 5.37.6 there is also the global variable C<${^FORCE_UPGRADE}>
which contains an empty string which when concatenated with any other
string causes the result to be an upgraded string. This can be helpful
in some contexts where explicitly calling this function might be
awkward. A similar effect can also be produced by using a C<\N{U+...}>
style escape for one of the characters in the string.

B<Note that this function does not handle arbitrary encodings>;
use L<Encode> instead.

Expand Down
5 changes: 5 additions & 0 deletions pod/perldelta.pod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ here, but most should go in the L</Performance Enhancements> section.

[ List each enhancement as a =head2 entry ]

=head2 New global variable C<${^FORCE_UPGRADE}>

This variable contains the empty string, and can be used to force a string
or pattern to be upgraded via concatenation.

=head1 Security

XXX Any security-related notices go here. In particular, any security
Expand Down
13 changes: 13 additions & 0 deletions pod/perlvar.pod
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,19 @@ mode is turned on. See L<perlrun|perlrun/-a> for the B<-a> switch. This
array is package-specific, and must be declared or given a full package
name if not in package main when running under C<strict 'vars'>.

=item ${^FORCE_UPGRADE}

This contains an empty string which when concatenated with any other
string will cause the result to be an upgraded string. Eg:

print "ss"=~/\xDF/i ? "yes" : "no";
no

but

print "ss"=~/\xDF${^FORCE_UPGRADE}/i ? "yes" : "no";
yes

=item @INC
X<@INC>

Expand Down