diff options
author | Karl Williamson <khw@cpan.org> | 2018-08-06 16:46:37 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2018-08-20 10:51:56 -0600 |
commit | 3a0825d5befb293a2031be8487afdb5440b9d6b6 (patch) | |
tree | 265ff07331f5bed4a8ff4d4c23d923df6f359350 | |
parent | 3b9fb37400e38d82b5690e90461199c0fab75d8f (diff) | |
download | perl-3a0825d5befb293a2031be8487afdb5440b9d6b6.tar.gz |
t/re/regexp_unicode_prop.t: Extract code into a function
This is in preparation for it to be called from a 2nd place
-rw-r--r-- | t/re/regexp_unicode_prop.t | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/t/re/regexp_unicode_prop.t b/t/re/regexp_unicode_prop.t index 4fba2ea50e..3c6e55b458 100644 --- a/t/re/regexp_unicode_prop.t +++ b/t/re/regexp_unicode_prop.t @@ -16,6 +16,27 @@ BEGIN { sub run_tests; +sub get_str_name($) { + my $char = shift; + + my ($str, $name); + + if ($char =~ /^\\/) { + $str = eval qq ["$char"]; + $name = qq ["$char"]; + } + elsif ($char =~ /^0x([0-9A-Fa-f]+)$/) { + $str = chr hex $1; + $name = "chr ($char)"; + } + else { + $str = $char; + $name = qq ["$char"]; + } + + return ($str, $name); +} + # # This is the data to test. # @@ -188,20 +209,7 @@ sub match { $caseless = "" unless defined $caseless; $caseless = 'i' if $caseless; - my ($str, $name); - - if ($char =~ /^\\/) { - $str = eval qq ["$char"]; - $name = qq ["$char"]; - } - elsif ($char =~ /^0x([0-9A-Fa-f]+)$/) { - $str = chr hex $1; - $name = "chr ($char)"; - } - else { - $str = $char; - $name = qq ["$char"]; - } + my ($str, $name) = get_str_name($char); undef $@; my $pat = "qr/$match/$caseless"; |