File Coverage

blib/lib/TeX/Hyphen/czech.pm
Criterion Covered Total %
statement 41 43 95.3
branch 14 16 87.5
condition 2 3 66.6
subroutine 4 4 100.0
pod 2 3 66.6
total 63 69 91.3


line stmt bran cond sub pod time code
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             my %BACKV = ( 'c' => 'è', 'd' => 'ï', 'e' => 'ì', 'l' => 'µ',
63             'n' => 'ò', 'r' => 'ø', 's' => '¹', 't' => '»', 'z' => '¾',
64             'C' => 'È', 'D' => 'Ï', 'E' => 'Ì', 'L' => '¥', 'N' => 'Ò',
65             'R' => 'Ø', 'S' => '©', 'T' => '«', 'Z' => '®' );
66             my %BACKAP = ( 'a' => 'á', 'e' => 'é', 'i' => 'í', 'l' => 'å',
67             'o' => 'ó', 'u' => 'ú', 'y' => 'ý', 'A' => 'Á', 'E' => 'É',
68             'I' => 'Í', 'L' => 'Å', 'O' => 'Ó', 'U' => 'Ú', 'Y' => 'Ý');
69             sub cstolower {
70 22313     22313 0 33239 my $e = shift;
71 22313         29607 $e =~ tr/[A-Z]ÁÄÈÏÉÌËÍÅ¥ÒÓÔÕÖØ©«ÚÙÛÜݬ®/[a-z]áäèïéìëíåµòóôõöø¹»úùûüý¼¾/;
72 22313         47638 $e;
73             }
74              
75 2     2   12 use vars qw( $LEFTMIN $RIGHTMIN $VERSION );
  2         3  
  2         1614  
76             $VERSION = 0.121;
77             $LEFTMIN = 2;
78             $RIGHTMIN = 2;
79              
80             sub process_patterns {
81 22250     22250 1 36330 my ($line, $bothhyphen, $beginhyphen, $endhyphen, $hyphen) = @_;
82              
83 22250 100       52645 if ($line =~ /\}/) {
84 7         97 return 0;
85             }
86              
87 22243         67294 for (split /\s+/, $line) {
88 22243 50       48247 next if $_ eq '';
89              
90 22243         26266 my $begin = 0;
91 22243         23737 my $end = 0;
92              
93 22243 100       49759 $begin = 1 if s!^\.!!;
94 22243 100       47327 $end = 1 if s!\.$!!;
95 22243         26259 s!\\v\s+(.)!$BACKV{$1}!g; # process the \v tag
96 22243         24706 s!\\'(.)!$BACKAP{$1}!g; # process the \' tag
97 22243         23965 s!\^\^(..)!chr(hex($1))!eg;
  0         0  
98             # convert things like ^^fc
99 22243         158288 s!(\D)(?=\D)!${1}0!g; # insert zeroes
100 22243         58036 s!^(?=\D)!0!; # and start with some digit
101            
102 22243         96563 ($tag = $_) =~ s!\d!!g; # get the string
103 22243         82652 ($value = $_) =~ s!\D!!g; # and numbers apart
104 22243         42586 $tag = cstolower($tag); # convert to lowercase
105             # (if we knew locales are fine everywhere,
106             # we could use them)
107            
108 22243 50 66     91167 if ($begin and $end) {
    100          
    100          
109 0         0 $bothhyphen->{$tag} = $value;
110             } elsif ($begin) {
111 995         3462 $beginhyphen->{$tag} = $value;
112             } elsif ($end) {
113 901         3281 $endhyphen->{$tag} = $value;
114             } else {
115 20347         74573 $hyphen->{$tag} = $value;
116             }
117             }
118              
119 22243         210651 1;
120             }
121              
122             sub process_hyphenation {
123 75     75 1 109 my ($line, $exception) = @_;
124              
125 75 100       218 if ($line =~ /\}/) {
126 5         57 return 0;
127             }
128              
129 70         112 local $_ = $line;
130              
131 70         100 s!\\v\s+(.)!$BACKV{$+}!g;
132 70         73 s!\\'(.)!$BACKAP{$+}!g;
133              
134 70         198 ($tag = $_) =~ s!-!!g;
135 70         130 $tag = cstolower($tag);
136 70         634 ($value = '0' . $_) =~ s![^-](?=[^-])!0!g;
137 70         239 $value =~ s![^-]-!1!g;
138 70         182 $value =~ s![^01]!0!g;
139            
140 70         186 $exception->{$tag} = $value;
141              
142 70         616 return 1;
143             }
144              
145             1;