summaryrefslogtreecommitdiff
path: root/regen
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2014-04-16 19:27:39 -0600
committerKarl Williamson <khw@cpan.org>2014-05-31 10:14:20 -0600
commita1beba5bf133a5abd1f8a0cb6054bec2c71d5619 (patch)
tree38e64d6b08ccab06fb3d80e59ff3d011cbb0a088 /regen
parente8fa43e2ca41ae473bc46c1faaddd42b50dbedcf (diff)
downloadperl-a1beba5bf133a5abd1f8a0cb6054bec2c71d5619.tar.gz
regen/unicode_constants.pl: Rearrange code order
This just changes the ordering so we don't do UTF-8 calculations unless needed.
Diffstat (limited to 'regen')
-rw-r--r--regen/unicode_constants.pl18
1 files changed, 11 insertions, 7 deletions
diff --git a/regen/unicode_constants.pl b/regen/unicode_constants.pl
index abf252386c..2924ff481d 100644
--- a/regen/unicode_constants.pl
+++ b/regen/unicode_constants.pl
@@ -108,10 +108,18 @@ while ( <DATA> ) {
$name = $desired_name if $name eq "" && $desired_name;
$name =~ s/[- ]/_/g; # The macro name can have no blanks nor dashes
- my $str = join "", map { sprintf "\\x%02X", $_ }
+ my $str;
+ my $suffix;
+ if (defined $flag && $flag eq 'native') {
+ die "Are you sure you want to run this on an above-Latin1 code point?" if $cp > 0xff;
+ $suffix = '_NATIVE';
+ $str = sprintf "0x%02X", $cp; # Is a numeric constant
+ }
+ else {
+ $str = join "", map { sprintf "\\x%02X", $_ }
unpack("U0C*", pack("U", $cp));
- my $suffix = '_UTF8';
+ $suffix = '_UTF8';
if (! defined $flag || $flag =~ /^ string (_skip_if_undef)? $/x) {
$str = "\"$str\""; # Will be a string constant
} elsif ($flag eq 'tail') {
@@ -124,14 +132,10 @@ while ( <DATA> ) {
$suffix .= '_FIRST_BYTE';
$str = "0x$str"; # Is a numeric constant
}
- elsif ($flag eq 'native') {
- die "Are you sure you want to run this on an above-Latin1 code point?" if $cp > 0xff;
- $suffix = '_NATIVE';
- $str = sprintf "0x%02X", $cp; # Is a numeric constant
- }
else {
die "Unknown flag at line $.: $_\n";
}
+ }
printf $out_fh "#define %s%s %s /* U+%04X */\n", $name, $suffix, $str, $U_cp;
}