File: CaseFoldPP.pm

package info (click to toggle)
libunicode-casefold-perl 1.01-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 352 kB
  • sloc: perl: 366; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 547 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package Unicode::CaseFold;

use strict;
use warnings;
use 5.008001;

use Unicode::UCD ();

our $SIMPLE_FOLDING = $^V lt v5.10.0;

sub case_fold {
  my ($string) = @_;

  my $WHICH_MAPPING = ($SIMPLE_FOLDING ? 'mapping' : 'full');

  my $out = "";

  for my $codepoint (unpack "U*", $string) {
    my $mapping = Unicode::UCD::casefold($codepoint);
    my @cp;
    if (!defined $mapping) {
      @cp = ($codepoint);
    } else {
      @cp = map hex, split / /, $mapping->{$WHICH_MAPPING};
    }
    $out .= pack "U*", @cp;
  }

  return $out;
}

1;