From 632c9f80dfaf91e6a695c9a916ab6136110e4ac7 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sun, 16 Dec 2012 08:56:28 -0700 Subject: [PATCH] regen/unicode_constants.pl: Add option to skip if undef I thought I would need this new functionality in this regen script, but ended up going a different route. But just in case someone might find this useful in the future, here it is. --- regen/unicode_constants.pl | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/regen/unicode_constants.pl b/regen/unicode_constants.pl index 729bde8..48b43f4 100644 --- a/regen/unicode_constants.pl +++ b/regen/unicode_constants.pl @@ -39,6 +39,9 @@ END # white space from the initial token. # string indicates that the output is to be of the string form # described in the comments above that are placed in the file. +# string_skip_ifundef is the same as 'string', but instead of dying if the +# code point doesn't exist, the line is just skipped: no output is +# generated for it # first indicates that the output is to be of the FIRST_BYTE form. # tail indicates that the output is of the _TAIL form. # native indicates that the output is the code point, converted to the @@ -72,6 +75,7 @@ while ( ) { my $name; my $cp; + my $undef_ok = $desired_name || $flag =~ /skip_if_undef/; if ($name_or_cp =~ /[^[:xdigit:]]/) { @@ -82,20 +86,23 @@ while ( ) { } else { $cp = $name_or_cp; - $name = charnames::viacode("0$cp") // ""; # viacode requires a leading - # zero to be sure that the - # argument is hex - die "Unknown code point '$cp' at line $.: $_\n" unless defined $cp; + $name = charnames::viacode("0$cp"); # viacode requires a leading zero + # to be sure that the argument is + # hex + if (! defined $name) { + die "Unknown code point '$cp' at line $.: $_\n" unless $undef_ok; + $name = ""; + } } - $name = $desired_name if $name eq ""; + $name = $desired_name if $name eq "" && $desired_name; $name =~ s/ /_/g; # The macro name can have no blanks in it my $str = join "", map { sprintf "\\x%02X", $_ } unpack("U0C*", pack("U", hex $cp)); my $suffix = '_UTF8'; - if (! defined $flag || $flag eq 'string') { + if (! defined $flag || $flag =~ /^ string (_skip_if_undef)? $/x) { $str = "\"$str\""; # Will be a string constant } elsif ($flag eq 'tail') { $str =~ s/\\x..//; # Remove the first byte -- 2.7.4