From a1beba5bf133a5abd1f8a0cb6054bec2c71d5619 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Wed, 16 Apr 2014 19:27:39 -0600 Subject: regen/unicode_constants.pl: Rearrange code order This just changes the ordering so we don't do UTF-8 calculations unless needed. --- regen/unicode_constants.pl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'regen') 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 ( ) { $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 ( ) { $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; } -- cgit v1.2.1