summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2012-12-16 08:56:28 -0700
committerKarl Williamson <public@khwilliamson.com>2012-12-16 11:03:29 -0700
commit632c9f80dfaf91e6a695c9a916ab6136110e4ac7 (patch)
treeeebfc8de1a2bda1113590fa5e7d9d6e72cd9c3cc
parent7d43c479c5220d368a2e5d94341c40f8d4cb1769 (diff)
downloadperl-632c9f80dfaf91e6a695c9a916ab6136110e4ac7.tar.gz
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.
-rw-r--r--regen/unicode_constants.pl19
1 files changed, 13 insertions, 6 deletions
diff --git a/regen/unicode_constants.pl b/regen/unicode_constants.pl
index 729bde8832..48b43f440e 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 ( <DATA> ) {
my $name;
my $cp;
+ my $undef_ok = $desired_name || $flag =~ /skip_if_undef/;
if ($name_or_cp =~ /[^[:xdigit:]]/) {
@@ -82,20 +86,23 @@ while ( <DATA> ) {
}
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