line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#-*- perl -*- |
2
|
|
|
|
|
|
|
#-*- coding: utf-8 -*- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Unicode::Precis; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
27956
|
use 5.008007; # Use Unicode 4.1.0 or later. |
|
1
|
|
|
|
|
3
|
|
7
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
43
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
2879
|
use Encode qw(is_utf8 _utf8_on _utf8_off); |
|
1
|
|
|
|
|
14352
|
|
|
1
|
|
|
|
|
96
|
|
11
|
1
|
|
|
1
|
|
722
|
use Unicode::BiDiRule qw(check); |
|
1
|
|
|
|
|
641
|
|
|
1
|
|
|
|
|
63
|
|
12
|
1
|
|
|
1
|
|
862
|
use Unicode::Normalize qw(normalize); |
|
1
|
|
|
|
|
2335
|
|
|
1
|
|
|
|
|
86
|
|
13
|
1
|
|
|
1
|
|
778
|
use Unicode::Precis::Preparation qw(prepare FreeFormClass IdentifierClass); |
|
1
|
|
|
|
|
62928
|
|
|
1
|
|
|
|
|
98
|
|
14
|
|
|
|
|
|
|
use Unicode::Precis::Utils |
15
|
1
|
|
|
1
|
|
561
|
qw(compareExactly decomposeWidth foldCase mapSpace); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
704
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.000'; |
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') { |
55
|
0
|
|
|
|
|
|
foldCase($string); |
56
|
|
|
|
|
|
|
} |
57
|
0
|
0
|
|
|
|
|
if ($self->{NormalizationRule}) { |
58
|
0
|
0
|
|
|
|
|
if (is_utf8($string)) { |
59
|
|
|
|
|
|
|
$string = |
60
|
0
|
|
|
|
|
|
eval { normalize(uc $self->{NormalizationRule}, $string) }; |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} elsif ("\t" eq "\005") { # EBCDIC |
62
|
|
|
|
|
|
|
$string = Encode::decode('UTF-8', $string); |
63
|
|
|
|
|
|
|
$string = |
64
|
|
|
|
|
|
|
eval { normalize(uc $self->{NormalizationRule}, $string) }; |
65
|
|
|
|
|
|
|
$string = Encode::encode('UTF-8', $string) if defined $string; |
66
|
|
|
|
|
|
|
} else { |
67
|
0
|
|
|
|
|
|
_utf8_on($string); |
68
|
|
|
|
|
|
|
$string = |
69
|
0
|
|
|
|
|
|
eval { normalize(uc $self->{NormalizationRule}, $string) }; |
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
_utf8_off($string); |
71
|
|
|
|
|
|
|
} |
72
|
0
|
0
|
|
|
|
|
return undef unless defined $string; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
0
|
0
|
|
|
|
if (lc($self->{DirectionalityRule} || '') eq 'bidi') { |
75
|
0
|
0
|
|
|
|
|
return undef unless defined check($string, 0); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
my $stringclass = { |
78
|
|
|
|
|
|
|
freeformclass => FreeFormClass, |
79
|
|
|
|
|
|
|
identifierclass => IdentifierClass, |
80
|
0
|
|
0
|
|
|
|
}->{lc($self->{StringClass} || '')} |
81
|
|
|
|
|
|
|
|| 0; |
82
|
|
|
|
|
|
|
return undef |
83
|
0
|
0
|
|
|
|
|
unless defined prepare($string, $stringclass); |
84
|
0
|
0
|
|
|
|
|
if (ref $self->{OtherRule} eq 'CODE') { |
85
|
|
|
|
|
|
|
return undef |
86
|
0
|
0
|
|
|
|
|
unless defined($string = $self->{OtherRule}->($string)); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
eval { $_[1] = $string }; |
|
0
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$string; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
__END__ |