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 14974 my $e = shift;
71 22313         14115 $e =~ tr/[A-Z]ÁÄÈÏÉÌËÍÅ¥ÒÓÔÕÖØ©«ÚÙÛÜݬ®/[a-z]áäèïéìëíåµòóôõöø¹»úùûüý¼¾/;
72 22313         21153 $e;
73             }
74              
75 2     2   7 use vars qw( $LEFTMIN $RIGHTMIN $VERSION );
  2         2  
  2         816  
76             $VERSION = 0.121;
77             $LEFTMIN = 2;
78             $RIGHTMIN = 2;
79              
80             sub process_patterns {
81 22250     22250 1 18436 my ($line, $bothhyphen, $beginhyphen, $endhyphen, $hyphen) = @_;
82              
83 22250 100       26821 if ($line =~ /\}/) {
84 7         42 return 0;
85             }
86              
87 22243         24602 for (split /\s+/, $line) {
88 22243 50       22754 next if $_ eq '';
89              
90 22243         12851 my $begin = 0;
91 22243         12256 my $end = 0;
92              
93 22243 100       26024 $begin = 1 if s!^\.!!;
94 22243 100       24623 $end = 1 if s!\.$!!;
95 22243         13508 s!\\v\s+(.)!$BACKV{$1}!g; # process the \v tag
96 22243         12147 s!\\'(.)!$BACKAP{$1}!g; # process the \' tag
97 22243         12806 s!\^\^(..)!chr(hex($1))!eg;
  0         0  
98             # convert things like ^^fc
99 22243         73323 s!(\D)(?=\D)!${1}0!g; # insert zeroes
100 22243         28244 s!^(?=\D)!0!; # and start with some digit
101            
102 22243         47776 ($tag = $_) =~ s!\d!!g; # get the string
103 22243         41985 ($value = $_) =~ s!\D!!g; # and numbers apart
104 22243         20718 $tag = cstolower($tag); # convert to lowercase
105             # (if we knew locales are fine everywhere,
106             # we could use them)
107            
108 22243 50 66     44782 if ($begin and $end) {
    100          
    100          
109 0         0 $bothhyphen->{$tag} = $value;
110             } elsif ($begin) {
111 995         2451 $beginhyphen->{$tag} = $value;
112             } elsif ($end) {
113 901         1711 $endhyphen->{$tag} = $value;
114             } else {
115 20347         37903 $hyphen->{$tag} = $value;
116             }
117             }
118              
119 22243         106526 1;
120             }
121              
122             sub process_hyphenation {
123 75     75 1 57 my ($line, $exception) = @_;
124              
125 75 100       95 if ($line =~ /\}/) {
126 5         25 return 0;
127             }
128              
129 70         57 local $_ = $line;
130              
131 70         47 s!\\v\s+(.)!$BACKV{$+}!g;
132 70         35 s!\\'(.)!$BACKAP{$+}!g;
133              
134 70         97 ($tag = $_) =~ s!-!!g;
135 70         60 $tag = cstolower($tag);
136 70         294 ($value = '0' . $_) =~ s![^-](?=[^-])!0!g;
137 70         112 $value =~ s![^-]-!1!g;
138 70         87 $value =~ s![^01]!0!g;
139            
140 70         88 $exception->{$tag} = $value;
141              
142 70         309 return 1;
143             }
144              
145             1;