| 1 | #-*- perl -*- | ||||||||||||||||||||||||
| 2 | #-*- coding: utf-8 -*- | ||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||
| 4 | package Unicode::Precis; | ||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||
| 6 | 1 | ▶ | use 5.008007; # Use Unicode 4.1.0 or later. | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | 1 | ▶ | use Encode qw(is_utf8 _utf8_on _utf8_off); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 11 | 1 | ▶ | use Unicode::BiDiRule qw(check); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 12 | 1 | ▶ | use Unicode::Normalize qw(normalize); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 13 | 1 | ▶ | use Unicode::Precis::Preparation qw(prepare FreeFormClass IdentifierClass); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 14 | use Unicode::Precis::Utils | ||||||||||||||||||||||||
| 15 | 1 | ▶ | qw(compareExactly decomposeWidth foldCase lowerCase mapSpace); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||
| 17 | 1 | our $VERSION = '1.199_01'; | |||||||||||||||||||||||
| 18 | 1 | $VERSION = eval $VERSION; # see L<perlmodstyle> | |||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||
| 21 | 0 | my $class = shift; | |||||||||||||||||||||||
| 22 | 0 | my %options = @_; | |||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||
| 24 | 0 | bless {%options} => $class; | |||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||
| 27 | 0 | ▶ | sub compare { | ||||||||||||||||||||||
|
Subroutine
compare: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||
| 28 | 0 | 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 | 0 | ▶ | sub enforce { | ||||||||||||||||||||||
|
Subroutine
enforce: not called CC=23 SCAR=63.1
Pod
documented
| |||||||||||||||||||||||||
| 36 | 0 | my ($self, $string) = @_; | |||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||
| 38 | 0 | ▶ | return undef unless defined $string; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||
| 40 | 0 | ▶ | if (lc($self->{WidthMappingRule} || '') eq 'decomposition') { | ||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{'WidthMappingRule'} || ''
MC/DC0%0/1
$self->{'WidthMappingRule'} || ''
$self->{'WidthMappingRule'}
Truth table0%0/2
A
A= $self->{'WidthMappingRule'}
| |||||||||||||||||||||||||
| 41 | 0 | decomposeWidth($string); | |||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||
| 43 | 0 | ▶ | my $mappingrule = lc($self->{AdditionalMappingRule} || ''); | ||||||||||||||||||||||
|
Condition0%0/2
$self->{'AdditionalMappingRule'} || ''
MC/DC0%0/1
$self->{'AdditionalMappingRule'} || ''
$self->{'AdditionalMappingRule'}
Truth table0%0/2
A
A= $self->{'AdditionalMappingRule'}
| |||||||||||||||||||||||||
| 44 | 0 | ▶ | if ($mappingrule =~ /\bmapspace/) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 45 | 0 | mapSpace($string); | |||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||
| 47 | 0 | ▶ | if ($mappingrule =~ /\bstripspace/) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 48 | 0 | $string =~ s/\A\x20+//; | |||||||||||||||||||||||
| 49 | 0 | $string =~ s/\x20+\z//; | |||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($mappingrule =~ /\bunifyspace/) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 52 | 0 | $string =~ s/\x20\x20+/\x20/g; | |||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||
| 54 | 0 | ▶ | if (lc($self->{CaseMappingRule} || '') eq 'fold') { | ||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/2
$self->{'CaseMappingRule'} || ''
MC/DC0%0/1
$self->{'CaseMappingRule'} || ''
$self->{'CaseMappingRule'}
Truth table0%0/2
A
A= $self->{'CaseMappingRule'}
| |||||||||||||||||||||||||
| 55 | 0 | foldCase($string); | |||||||||||||||||||||||
| 56 | ▶ | } elsif (lc($self->{CaseMappingRule} || '') eq 'lower') { | |||||||||||||||||||||||
|
Condition0%0/2
$self->{'CaseMappingRule'} || ''
MC/DC0%0/1
$self->{'CaseMappingRule'} || ''
$self->{'CaseMappingRule'}
Truth table0%0/2
A
A= $self->{'CaseMappingRule'}
| |||||||||||||||||||||||||
| 57 | 0 | lowerCase($string); | |||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($self->{NormalizationRule}) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 60 | 0 | ▶ | if (is_utf8($string)) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 61 | $string = | ||||||||||||||||||||||||
| 62 | 0 | eval { normalize(uc $self->{NormalizationRule}, $string) }; | |||||||||||||||||||||||
| 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) }; | |||||||||||||||||||||||
| 72 | 0 | _utf8_off($string); | |||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||
| 74 | 0 | ▶ | return undef unless defined $string; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||
| 76 | 0 | ▶ | if (lc($self->{DirectionalityRule} || '') eq 'bidi') { | ||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{'DirectionalityRule'} || ''
MC/DC0%0/1
$self->{'DirectionalityRule'} || ''
$self->{'DirectionalityRule'}
Truth table0%0/2
A
A= $self->{'DirectionalityRule'}
| |||||||||||||||||||||||||
| 77 | 0 | ▶ | return undef unless defined check($string, 0); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||
| 79 | my $stringclass = { | ||||||||||||||||||||||||
| 80 | freeformclass => FreeFormClass, | ||||||||||||||||||||||||
| 81 | identifierclass => IdentifierClass, | ||||||||||||||||||||||||
| 82 | 0 | ▶ | }->{lc($self->{StringClass} || '')} | ||||||||||||||||||||||
|
Condition0%0/4
{'freeformclass', FreeFormClass(), 'identifierclass', IdentifierClass()}->{lc($self->{'StringClass'} || '')} || 0
$self->{'StringClass'} || ''
MC/DC0%0/1
{'freeformclass', FreeFormClass(), 'identifierclass', IdentifierClass()}->{lc($self->{'StringClass'} || '')} || 0
{'freeformclass', FreeFormClass(), 'identifierclass', IdentifierClass()}->{lc($self->{'StringClass'} || '')}
MC/DC0%0/1
$self->{'StringClass'} || ''
$self->{'StringClass'}
Truth table0%0/2
A
A= {'freeformclass', FreeFormClass(), 'identifierclass', IdentifierClass()}->{lc($self->{'StringClass'} || '')}
Truth table0%0/2
A
A= $self->{'StringClass'}
| |||||||||||||||||||||||||
| 83 | || 0; | ||||||||||||||||||||||||
| 84 | return undef | ||||||||||||||||||||||||
| 85 | 0 | ▶ | unless defined prepare($string, $stringclass); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 86 | 0 | ▶ | if (ref $self->{OtherRule} eq 'CODE') { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 87 | return undef | ||||||||||||||||||||||||
| 88 | 0 | ▶ | unless defined($string = $self->{OtherRule}->($string)); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||
| 91 | 0 | eval { $_[1] = $string }; | |||||||||||||||||||||||
| 92 | 0 | $string; | |||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||
| 95 | 1 | 1; | |||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||