line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#-*- perl -*- |
2
|
|
|
|
|
|
|
#-*- coding: utf-8 -*- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Unicode::Precis; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
58002
|
use 5.008007; # Use Unicode 4.1.0 or later. |
|
1
|
|
|
|
|
4
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
463
|
use Encode qw(is_utf8 _utf8_on _utf8_off); |
|
1
|
|
|
|
|
8648
|
|
|
1
|
|
|
|
|
83
|
|
11
|
1
|
|
|
1
|
|
373
|
use Unicode::BiDiRule qw(check); |
|
1
|
|
|
|
|
566
|
|
|
1
|
|
|
|
|
54
|
|
12
|
1
|
|
|
1
|
|
490
|
use Unicode::Normalize qw(normalize); |
|
1
|
|
|
|
|
1793
|
|
|
1
|
|
|
|
|
78
|
|
13
|
1
|
|
|
1
|
|
446
|
use Unicode::Precis::Preparation qw(prepare FreeFormClass IdentifierClass); |
|
1
|
|
|
|
|
44641
|
|
|
1
|
|
|
|
|
89
|
|
14
|
|
|
|
|
|
|
use Unicode::Precis::Utils |
15
|
1
|
|
|
1
|
|
382
|
qw(compareExactly decomposeWidth foldCase lowerCase mapSpace); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
529
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.199_01'; |
18
|
|
|
|
|
|
|
$VERSION = eval $VERSION; # see L |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
22
|
0
|
|
|
|
|
|
my %options = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
bless {%options} => $class; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub compare { |
28
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
29
|
0
|
|
|
|
|
|
my $stringA = $self->enforce(shift); |
30
|
0
|
|
|
|
|
|
my $stringB = $self->enforce(shift); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
return compareExactly($stringA, $stringB); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub enforce { |
36
|
0
|
|
|
0
|
1
|
|
my ($self, $string) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
return undef unless defined $string; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
0
|
|
|
|
if (lc($self->{WidthMappingRule} || '') eq 'decomposition') { |
41
|
0
|
|
|
|
|
|
decomposeWidth($string); |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
0
|
|
|
|
my $mappingrule = lc($self->{AdditionalMappingRule} || ''); |
44
|
0
|
0
|
|
|
|
|
if ($mappingrule =~ /\bmapspace/) { |
45
|
0
|
|
|
|
|
|
mapSpace($string); |
46
|
|
|
|
|
|
|
} |
47
|
0
|
0
|
|
|
|
|
if ($mappingrule =~ /\bstripspace/) { |
48
|
0
|
|
|
|
|
|
$string =~ s/\A\x20+//; |
49
|
0
|
|
|
|
|
|
$string =~ s/\x20+\z//; |
50
|
|
|
|
|
|
|
} |
51
|
0
|
0
|
|
|
|
|
if ($mappingrule =~ /\bunifyspace/) { |
52
|
0
|
|
|
|
|
|
$string =~ s/\x20\x20+/\x20/g; |
53
|
|
|
|
|
|
|
} |
54
|
0
|
0
|
0
|
|
|
|
if (lc($self->{CaseMappingRule} || '') eq 'fold') { |
|
|
0
|
0
|
|
|
|
|
55
|
0
|
|
|
|
|
|
foldCase($string); |
56
|
|
|
|
|
|
|
} elsif (lc($self->{CaseMappingRule} || '') eq 'lower') { |
57
|
0
|
|
|
|
|
|
lowerCase($string); |
58
|
|
|
|
|
|
|
} |
59
|
0
|
0
|
|
|
|
|
if ($self->{NormalizationRule}) { |
60
|
0
|
0
|
|
|
|
|
if (is_utf8($string)) { |
61
|
|
|
|
|
|
|
$string = |
62
|
0
|
|
|
|
|
|
eval { normalize(uc $self->{NormalizationRule}, $string) }; |
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} elsif ("\t" eq "\005") { # EBCDIC |
64
|
|
|
|
|
|
|
$string = Encode::decode('UTF-8', $string); |
65
|
|
|
|
|
|
|
$string = |
66
|
|
|
|
|
|
|
eval { normalize(uc $self->{NormalizationRule}, $string) }; |
67
|
|
|
|
|
|
|
$string = Encode::encode('UTF-8', $string) if defined $string; |
68
|
|
|
|
|
|
|
} else { |
69
|
0
|
|
|
|
|
|
_utf8_on($string); |
70
|
|
|
|
|
|
|
$string = |
71
|
0
|
|
|
|
|
|
eval { normalize(uc $self->{NormalizationRule}, $string) }; |
|
0
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
_utf8_off($string); |
73
|
|
|
|
|
|
|
} |
74
|
0
|
0
|
|
|
|
|
return undef unless defined $string; |
75
|
|
|
|
|
|
|
} |
76
|
0
|
0
|
0
|
|
|
|
if (lc($self->{DirectionalityRule} || '') eq 'bidi') { |
77
|
0
|
0
|
|
|
|
|
return undef unless defined check($string, 0); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
my $stringclass = { |
80
|
|
|
|
|
|
|
freeformclass => FreeFormClass, |
81
|
|
|
|
|
|
|
identifierclass => IdentifierClass, |
82
|
0
|
|
0
|
|
|
|
}->{lc($self->{StringClass} || '')} |
83
|
|
|
|
|
|
|
|| 0; |
84
|
|
|
|
|
|
|
return undef |
85
|
0
|
0
|
|
|
|
|
unless defined prepare($string, $stringclass); |
86
|
0
|
0
|
|
|
|
|
if (ref $self->{OtherRule} eq 'CODE') { |
87
|
|
|
|
|
|
|
return undef |
88
|
0
|
0
|
|
|
|
|
unless defined($string = $self->{OtherRule}->($string)); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
eval { $_[1] = $string }; |
|
0
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$string; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
__END__ |