This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regen/regcharclass_multi_char_folds.pl: Use printable char
authorKarl Williamson <khw@cpan.org>
Thu, 14 Nov 2019 16:36:48 +0000 (09:36 -0700)
committerKarl Williamson <khw@cpan.org>
Sat, 16 Nov 2019 17:49:19 +0000 (10:49 -0700)
It makes the result more legible if it uses the printable character
instead of an escape sequence when appropriate.

Although, currently, the value is re-escaped for output.  This helped
during debugging.

regcharclass.h
regen/regcharclass_multi_char_folds.pl

index 54f3b10..f307fd7 100644 (file)
  * a712c758275b460d18fa77a26ed3589689bb3f69dcc1ea99b913e32db92a5cd2 lib/unicore/version
  * 2680b9254eb236c5c090f11b149605043e8c8433661b96efc4a42fb4709342a5 regen/charset_translations.pl
  * 8cffbf838b6e8ea5310e4ad2e0498ad9c1d87d4babead678081859473591317c regen/regcharclass.pl
- * 1ff734f7ad2d8d8fbbb2d091e5301da4b175a37fd1cbce553cd228035e98ec72 regen/regcharclass_multi_char_folds.pl
+ * 2bc7f79dc0257ad12db2288ccfcae7fa07bf0c068e4413b80f32c90d7dde0653 regen/regcharclass_multi_char_folds.pl
  * ex: set ro: */
index 9840eb9..a49dcb3 100644 (file)
@@ -45,7 +45,9 @@ sub gen_combinations ($;) {
     foreach my $j (0 .. @{$fold_ref->[$i]} - 1) {
 
         # Append its representation to what we have currently
-        my $new_string = sprintf "$string\\x{%X}", $fold_ref->[$i][$j];
+        my $new_string = $fold_ref->[$i][$j] =~ /[[:print:]]/
+                         ? ($string . chr $fold_ref->[$i][$j])
+                         : sprintf "$string\\x{%X}", $fold_ref->[$i][$j];
 
         if ($i >=  @$fold_ref - 1) {    # Final level: just return it
             push @ret, "\"$new_string\"";
@@ -83,8 +85,12 @@ sub multi_char_folds ($) {
         die sprintf("regcomp.c can't cope with a latin1 multi-char fold (found in the fold of 0x%X", $cp_ref->[$i]) if grep { $_ < 256 && chr($_) !~ /[[:ascii:]]/ } @{$folds_ref->[$i]};
 
         # Create a line that looks like "\x{foo}\x{bar}\x{baz}" of the code
-        # points that make up the fold.
-        my $fold = join "", map { sprintf "\\x{%X}", $_ } @{$folds_ref->[$i]};
+        # points that make up the fold (use the actual character if
+        # printable).
+        my $fold = join "", map { chr $_ =~ /[[:print:]]/a
+                                            ? chr $_
+                                            : sprintf "\\x{%X}", $_
+                                } @{$folds_ref->[$i]};
         $fold = "\"$fold\"";
 
         # Skip if something else already has this fold