Hyphen/czech.pm

filter: Statementstmt 95.9% 47 / 49 Branchbran 87.5% 14 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 4 / 4 Podpod 66.6% 2 / 3 totaltotal 89.6% 69 / 77 SCAR 24.0
CC
11
Cov
93%
process_patterns
10.2
process_hyphenation
2.0
cstolower
1.0
CRAP 11.0
« Hyphen/utf8.pm ↑ Summary
1  
2 package TeX::Hyphen::czech;
3  
4 =head1 NAME
5  
6 TeX::Hyphen::czech -- provides parsing routine for Czech patterns
7  
8 =head1 SYNOPSIS
9  
10 use TeX::Hyphen;
11 my $hyp = new TeX::Hyphen 'hyphen.tex', style => 'czech';
12  
13 # and then follow documentation for TeX::Hyphen
14  
15 =head1 DESCRIPTION
16  
17 This pattern processing happens to be the default. If you need to
18 write you own style of parsing the pattern file, you might want to
19 start with this file and hack it to suit your needs. There is nothing
20 for end users here -- just specify the style parameter in call to new
21 TeX::Hyphen.
22  
23 The language style specific modules have to define the following
24 functions:
25  
26 =over 4
27  
28 =item process_patterns
29  
30 This method gets individual lines of the \patterns content. It should
31 parse these lines, and fill values in $bothhyphen, $beginhyphen,
32 $endhyphen and $hyphen which are being passed to this function as
33 parameters following the line. The function should return 0 if end of
34 the pattern section (macro) was reached, 1 if the parsing should
35 continue.
36  
37 =item process_hyphenation
38  
39 This method gets the lines of the \hyphenation content. It should
40 parse these lines and fill values into $exception which is passed as
41 second parameter upon call. The function should return 0 if end of the
42 exception section (macro) was reached, 1 if the parsing should
43 continue.
44  
45 =back
46  
47 Check the TeX::Hyphen::czech source to see the exact form of the
48 values inserted into these has structures.
49  
50 Each style module should also define $LEFTMIN and $RIGHTMIN global
51 variables, if they have different values than the default 2. The
52 values should match the paratemers used to generate the patterns.
53 Since various pattern files could be generated with different values
54 set, this is just default that can be changed with parameters to the
55 TeX::Hyphen constructor.
56  
57 =cut
58  
59 # ######################################################
60 # TeX conversions done for Czech language, eg. \'a, \v r
61 #
62 2 my %BACKV = ( 'c' => 'è', 'd' => 'ï', 'e' => 'ì', 'l' => 'µ',
63 'n' => 'ò', 'r' => 'ø', 's' => '¹', 't' => '»', 'z' => '¾',
64 'C' => 'È', 'D' => 'Ï', 'E' => 'Ì', 'L' => '¥', 'N' => 'Ò',
65 'R' => 'Ø', 'S' => '©', 'T' => '«', 'Z' => '®' );
66 2 my %BACKAP = ( 'a' => 'á', 'e' => 'é', 'i' => 'í', 'l' => 'å',
67 'o' => 'ó', 'u' => 'ú', 'y' => 'ý', 'A' => 'Á', 'E' => 'É',
68 'I' => 'Í', 'L' => 'Å', 'O' => 'Ó', 'U' => 'Ú', 'Y' => 'Ý');
69 sub cstolower {
70 22313 ▶ my $e = shift;
Subroutine cstolower: called CC=1 SCAR=0.0
Pod undocumented
71 22313 $e =~ tr/[A-Z]ÁÄÈÏÉÌËÍÅ¥ÒÓÔÕÖØ©«ÚÙÛÜݬ®/[a-z]áäèïéìëíåµòóôõöø¹»úùûüý¼¾/;
72 22313 $e;
73 }
74  
75 2 ▶use vars qw( $LEFTMIN $RIGHTMIN $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
76 2 $VERSION = 0.121;
77 2 $LEFTMIN = 2;
78 2 $RIGHTMIN = 2;
79  
80 sub process_patterns {
81 22250 ▶ my ($line, $bothhyphen, $beginhyphen, $endhyphen, $hyphen) = @_;
Subroutine process_patterns: called CC=10 SCAR=23.2
Pod documented
82  
83 22250 ▶ if ($line =~ /\}/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\}/) 7 22243 22250
84 7 return 0;
85 }
86  
87 22243 for (split /\s+/, $line) {
88 22243 ▶ next if $_ eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "" 0 22243 22243
89  
90 22243 my $begin = 0;
91 22243 my $end = 0;
92  
93 22243 ▶ $begin = 1 if s!^\.!!;
Branch: 1 branch
BranchTrueFalseTotal
if s/^\.// 995 21248 22243
94 22243 ▶ $end = 1 if s!\.$!!;
Branch: 1 branch
BranchTrueFalseTotal
if s/\.$// 901 21342 22243
95 22243 s!\\v\s+(.)!$BACKV{$1}!g; # process the \v tag
96 22243 s!\\'(.)!$BACKAP{$1}!g; # process the \' tag
97 22243 s!\^\^(..)!chr(hex($1))!eg;
98 # convert things like ^^fc
99 22243 s!(\D)(?=\D)!${1}0!g; # insert zeroes
100 22243 s!^(?=\D)!0!; # and start with some digit
101
102 22243 ($tag = $_) =~ s!\d!!g; # get the string
103 22243 ($value = $_) =~ s!\D!!g; # and numbers apart
104 22243 $tag = cstolower($tag); # convert to lowercase
105 # (if we knew locales are fine everywhere,
106 # we could use them)
107
108 22243 ▶ if ($begin and $end) {
Branch: 3 branches
BranchTrueFalseTotal
if ($begin and $end) { } 0 22243 22243
elsif ($begin) { } 995 21248 22243
elsif ($end) { } 901 20347 21248
Condition66%2/3
$begin and $end
!ll&&!rl&&r
212489950
MC/DC0%0/2
$begin and $end
$begin $end
Truth table66%2/3
A and B
A= $beginB= $end
ABresult
0X0
100
111
109 0 $bothhyphen->{$tag} = $value;
110 } elsif ($begin) {
111 995 $beginhyphen->{$tag} = $value;
112 } elsif ($end) {
113 901 $endhyphen->{$tag} = $value;
114 } else {
115 20347 $hyphen->{$tag} = $value;
116 }
117 }
118  
119 22243 1;
120 }
121  
122 sub process_hyphenation {
123 75 ▶ my ($line, $exception) = @_;
Subroutine process_hyphenation: called CC=2 SCAR=6.9
Pod documented
124  
125 75 ▶ if ($line =~ /\}/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\}/) 5 70 75
126 5 return 0;
127 }
128  
129 70 local $_ = $line;
130  
131 70 s!\\v\s+(.)!$BACKV{$+}!g;
132 70 s!\\'(.)!$BACKAP{$+}!g;
133  
134 70 ($tag = $_) =~ s!-!!g;
135 70 $tag = cstolower($tag);
136 70 ($value = '0' . $_) =~ s![^-](?=[^-])!0!g;
137 70 $value =~ s![^-]-!1!g;
138 70 $value =~ s![^01]!0!g;
139
140 70 $exception->{$tag} = $value;
141  
142 70 return 1;
143 }
144  
145 2 1;
« Hyphen/utf8.pm ↑ Summary