| 1 | package Unicode::CaseFold; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use 5.008001; | ||
| 6 | |||
| 7 | use Unicode::UCD (); | ||
| 8 | |||
| 9 | our $SIMPLE_FOLDING = $^V lt v5.10.0; | ||
| 10 | |||
| 11 | sub case_fold { | ||
| 12 | my ($string) = @_; | ||
| 13 | |||
| 14 | my $WHICH_MAPPING = ($SIMPLE_FOLDING ? 'mapping' : 'full'); | ||
| 15 | |||
| 16 | my $out = ""; | ||
| 17 | |||
| 18 | for my $codepoint (unpack "U*", $string) { | ||
| 19 | my $mapping = Unicode::UCD::casefold($codepoint); | ||
| 20 | my @cp; | ||
| 21 | if (!defined $mapping) { | ||
| 22 | @cp = ($codepoint); | ||
| 23 | } else { | ||
| 24 | @cp = map hex, split / /, $mapping->{$WHICH_MAPPING}; | ||
| 25 | } | ||
| 26 | $out .= pack "U*", @cp; | ||
| 27 | } | ||
| 28 | |||
| 29 | return $out; | ||
| 30 | } | ||
| 31 | |||
| 32 | 1; |