File Coverage

blib/lib/TeX/Hyphen/utf8.pm
Criterion Covered Total %
statement 29 42 69.0
branch 11 18 61.1
condition 1 3 33.3
subroutine 4 5 80.0
pod 2 2 100.0
total 47 70 67.1


line stmt bran cond sub pod time code
1             package TeX::Hyphen::utf8;
2 1     1   9 use utf8;
  1         2  
  1         11  
3             =head1 NAME
4              
5             TeX::Hyphen::utf8 -- provides parsing routine for generic utf8 text
6              
7             =head1 SYNOPSIS
8              
9             use TeX::Hyphen;
10             my $hyp = new TeX::Hyphen 'hyphen.tex', style => 'utf8';
11              
12             # and then follow documentation for TeX::Hyphen
13              
14             =head1 DESCRIPTION
15              
16             This pattern is for utf8 pattern files.
17              
18             =over 4
19              
20             =item process_patterns
21              
22             This method gets individual lines of the \patterns content. It should
23             parse these lines, and fill values in $bothhyphen, $beginhyphen,
24             $endhyphen and $hyphen which are being passed to this function as
25             parameters following the line. The function should return 0 if end of
26             the pattern section (macro) was reached, 1 if the parsing should
27             continue.
28              
29             =item process_hyphenation
30              
31             This method gets the lines of the \hyphenation content. It should
32             parse these lines and fill values into $exception which is passed as
33             second parameter upon call. The function should return 0 if end of the
34             exception section (macro) was reached, 1 if the parsing should
35             continue.
36              
37             =back
38              
39             Check the TeX::Hyphen::czech source to see the exact form of the
40             values inserted into these has structures.
41              
42             Each style module should also define $LEFTMIN and $RIGHTMIN global
43             variables, if they have different values than the default 2. The
44             values should match the paratemers used to generate the patterns.
45             Since various pattern files could be generated with different values
46             set, this is just default that can be changed with parameters to the
47             TeX::Hyphen constructor.
48              
49             =cut
50              
51             # ######################################################
52              
53 1     1   87 use vars qw( $LEFTMIN $RIGHTMIN $VERSION );
  1         2  
  1         1007  
54             $VERSION = 0.121;
55             $LEFTMIN = 2;
56             $RIGHTMIN = 2;
57              
58             sub process_patterns {
59 4     4 1 12 my ($line, $bothhyphen, $beginhyphen, $endhyphen, $hyphen) = @_;
60              
61 4 100       21 if ($line =~ /\}/) {
62 1         32 return 0;
63             }
64              
65 3         22 for (split /\s+/, $line) {
66 3 50       13 next if $_ eq '';
67 3         7 my $orig = $_;
68              
69 3         7 my $begin = 0;
70 3         7 my $end = 0;
71              
72 3 50       13 $begin = 1 if s!^\.!!;
73 3 100       19 $end = 1 if s!\.$!!;
74 3         52 s!(\D)(?=\D)!${1}0!g; # insert zeroes
75 3         11 s!^(?=\D)!0!; # and start with some digit
76 3 50       14 print "$orig => $_\n" if ($TeX::Hyphen::DEBUG>5);
77            
78 3         23 ($tag = $_) =~ s!\d!!g; # get the string
79 3         17 ($value = $_) =~ s!\D!!g; # and numbers apart
80 1     1   11 $tag = lc($tag); # convert to lowercase
  1         3  
  1         19  
  3         65  
81             # (if we knew locales are fine everywhere,
82             # we could use them)
83            
84 3 50 33     34081 if ($begin and $end) {
    50          
    100          
85 0         0 $bothhyphen->{$tag} = $value;
86             } elsif ($begin) {
87 0         0 $beginhyphen->{$tag} = $value;
88             } elsif ($end) {
89 1         6 $endhyphen->{$tag} = $value;
90             } else {
91 2         12 $hyphen->{$tag} = $value;
92             }
93             }
94              
95 3         65 1;
96             }
97              
98             sub process_hyphenation {
99 0     0 1   my ($line, $exception) = @_;
100              
101 0 0         if ($line =~ /\}/) {
102 0           return 0;
103             }
104              
105 0           local $_ = $line;
106              
107 0           ($tag = $_) =~ s!-!!g;
108 0           $tag = lc($tag);
109 0           ($value = '0' . $_) =~ s![^-](?=[^-])!0!g;
110 0           $value =~ s![^-]-!1!g;
111 0           $value =~ s![^01]!0!g;
112            
113 0           $exception->{$tag} = $value;
114              
115 0           return 1;
116             }
117              
118             1;