line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#-*- perl -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Unicode::LineBreak; |
4
|
|
|
|
|
|
|
require 5.008; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
### Pragmas: |
7
|
21
|
|
|
21
|
|
368241
|
use strict; |
|
21
|
|
|
|
|
71
|
|
|
21
|
|
|
|
|
611
|
|
8
|
21
|
|
|
21
|
|
106
|
use warnings; |
|
21
|
|
|
|
|
45
|
|
|
21
|
|
|
|
|
646
|
|
9
|
21
|
|
|
21
|
|
112
|
use vars qw($VERSION @EXPORT_OK @ISA $Config @Config); |
|
21
|
|
|
|
|
43
|
|
|
21
|
|
|
|
|
1717
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
### Exporting: |
12
|
21
|
|
|
21
|
|
142
|
use Exporter; |
|
21
|
|
|
|
|
42
|
|
|
21
|
|
|
|
|
1796
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw(UNICODE_VERSION SOMBOK_VERSION context); |
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = ('all' => [@EXPORT_OK]); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
### Inheritance: |
17
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
### Other modules: |
20
|
21
|
|
|
21
|
|
147
|
use Carp qw(croak carp); |
|
21
|
|
|
|
|
65
|
|
|
21
|
|
|
|
|
1269
|
|
21
|
21
|
|
|
21
|
|
1949
|
use Encode qw(is_utf8); |
|
21
|
|
|
|
|
30779
|
|
|
21
|
|
|
|
|
1249
|
|
22
|
21
|
|
|
21
|
|
9966
|
use MIME::Charset; |
|
21
|
|
|
|
|
94638
|
|
|
21
|
|
|
|
|
1563
|
|
23
|
21
|
|
|
21
|
|
8252
|
use Unicode::GCString; |
|
21
|
|
|
|
|
51
|
|
|
21
|
|
|
|
|
2959
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
### Globals |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
### The package version |
28
|
|
|
|
|
|
|
our $VERSION = '2018.012'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
### Public Configuration Attributes |
31
|
|
|
|
|
|
|
our @Config = ( |
32
|
|
|
|
|
|
|
BreakIndent => 'YES', |
33
|
|
|
|
|
|
|
CharMax => 998, |
34
|
|
|
|
|
|
|
ColMax => 76, |
35
|
|
|
|
|
|
|
ColMin => 0, |
36
|
|
|
|
|
|
|
ComplexBreaking => 'YES', |
37
|
|
|
|
|
|
|
Context => 'NONEASTASIAN', |
38
|
|
|
|
|
|
|
EAWidth => undef, |
39
|
|
|
|
|
|
|
Format => 'SIMPLE', |
40
|
|
|
|
|
|
|
HangulAsAL => 'NO', |
41
|
|
|
|
|
|
|
LBClass => undef, |
42
|
|
|
|
|
|
|
LegacyCM => 'YES', |
43
|
|
|
|
|
|
|
Newline => "\n", |
44
|
|
|
|
|
|
|
Prep => undef, |
45
|
|
|
|
|
|
|
Sizing => 'UAX11', |
46
|
|
|
|
|
|
|
Urgent => undef, |
47
|
|
|
|
|
|
|
ViramaAsJoiner => 'YES', |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
our $Config = {}; |
50
|
|
|
|
|
|
|
eval { require Unicode::LineBreak::Defaults; }; |
51
|
|
|
|
|
|
|
push @Config, (%$Config); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
### Exportable constants |
54
|
21
|
|
|
21
|
|
9212
|
use Unicode::LineBreak::Constants; |
|
21
|
|
|
|
|
63
|
|
|
21
|
|
|
|
|
636
|
|
55
|
21
|
|
|
21
|
|
123
|
use constant 1.01; |
|
21
|
|
|
|
|
362
|
|
|
21
|
|
|
|
|
2959
|
|
56
|
|
|
|
|
|
|
my $package = __PACKAGE__; |
57
|
|
|
|
|
|
|
my @consts = grep { s/^${package}::(\w\w+)$/$1/ } keys %constant::declared; |
58
|
|
|
|
|
|
|
push @EXPORT_OK, @consts; |
59
|
|
|
|
|
|
|
push @{$EXPORT_TAGS{'all'}}, @consts; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
### Load XS module |
62
|
|
|
|
|
|
|
require XSLoader; |
63
|
|
|
|
|
|
|
XSLoader::load('Unicode::LineBreak', $VERSION); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
### Load dynamic constants |
66
|
|
|
|
|
|
|
foreach my $p ((['EA', EAWidths()], ['LB', LBClasses()])) { |
67
|
|
|
|
|
|
|
my $prop = shift @{$p}; |
68
|
|
|
|
|
|
|
my $idx = 0; |
69
|
|
|
|
|
|
|
foreach my $val (@{$p}) { |
70
|
21
|
|
|
21
|
|
133
|
no strict; |
|
21
|
|
|
|
|
39
|
|
|
21
|
|
|
|
|
4440
|
|
71
|
|
|
|
|
|
|
my $const = "${prop}_${val}"; |
72
|
0
|
|
|
0
|
|
0
|
*{$const} = eval "sub { $idx }"; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
1273
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
2642
|
|
|
|
|
9746
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
1556
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
2125
|
|
|
0
|
|
|
|
|
0
|
|
|
677
|
|
|
|
|
3750
|
|
|
0
|
|
|
|
|
0
|
|
|
5
|
|
|
|
|
2187
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
1170
|
|
|
1
|
|
|
|
|
1286
|
|
|
0
|
|
|
|
|
0
|
|
|
2
|
|
|
|
|
2459
|
|
|
2
|
|
|
|
|
2429
|
|
|
2
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
1214
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
1237
|
|
|
1
|
|
|
|
|
1186
|
|
|
1
|
|
|
|
|
1190
|
|
|
4
|
|
|
|
|
2256
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
6
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
1254
|
|
|
0
|
|
|
|
|
0
|
|
|
44
|
|
|
|
|
25158
|
|
|
0
|
|
|
|
|
0
|
|
73
|
|
|
|
|
|
|
push @EXPORT_OK, $const; |
74
|
|
|
|
|
|
|
push @{$EXPORT_TAGS{'all'}}, $const; |
75
|
|
|
|
|
|
|
$idx++; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
### Privates |
80
|
|
|
|
|
|
|
my $EASTASIAN_CHARSETS = qr{ |
81
|
|
|
|
|
|
|
^BIG5 | |
82
|
|
|
|
|
|
|
^CP9\d\d | |
83
|
|
|
|
|
|
|
^EUC- | |
84
|
|
|
|
|
|
|
^GB18030 | ^GB2312 | ^GBK | |
85
|
|
|
|
|
|
|
^HZ | |
86
|
|
|
|
|
|
|
^ISO-2022- | |
87
|
|
|
|
|
|
|
^KS_C_5601 | |
88
|
|
|
|
|
|
|
^SHIFT_JIS |
89
|
|
|
|
|
|
|
}ix; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $EASTASIAN_LANGUAGES = qr{ |
92
|
|
|
|
|
|
|
^AIN | |
93
|
|
|
|
|
|
|
^JA\b | ^JPN | |
94
|
|
|
|
|
|
|
^KO\b | ^KOR | |
95
|
|
|
|
|
|
|
^ZH\b | ^CHI |
96
|
|
|
|
|
|
|
}ix; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
use overload |
99
|
21
|
|
|
|
|
186
|
'%{}' => \&as_hashref, |
100
|
|
|
|
|
|
|
'${}' => \&as_scalarref, |
101
|
|
|
|
|
|
|
'""' => \&as_string, |
102
|
21
|
|
|
21
|
|
2591
|
; |
|
21
|
|
|
|
|
1963
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub new { |
105
|
483
|
|
|
483
|
1
|
154509
|
my $class = shift; |
106
|
|
|
|
|
|
|
|
107
|
483
|
|
|
|
|
2088
|
my $self = __PACKAGE__->_new(); |
108
|
483
|
|
|
|
|
1573
|
$self->config(@Config); |
109
|
483
|
|
|
|
|
1614
|
$self->config(@_); |
110
|
483
|
|
|
|
|
1494
|
bless $self, $class; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub config ($@) { |
114
|
1398
|
|
|
1398
|
1
|
2229
|
my $self = shift; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Get config. |
117
|
1398
|
100
|
|
|
|
3208
|
if (scalar @_ == 1) { |
118
|
353
|
|
|
|
|
521
|
my $k = shift; |
119
|
353
|
|
|
|
|
466
|
my $ret; |
120
|
|
|
|
|
|
|
|
121
|
353
|
50
|
|
|
|
1603
|
if (uc $k eq uc 'CharactersMax') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
122
|
0
|
|
|
|
|
0
|
return $self->_config('CharMax'); |
123
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'ColumnsMax') { |
124
|
0
|
|
|
|
|
0
|
return $self->_config('ColMax'); |
125
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'ColumnsMin') { |
126
|
0
|
|
|
|
|
0
|
return $self->_config('ColMin'); |
127
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'SizingMethod') { |
128
|
0
|
|
|
|
|
0
|
return $self->_config('Sizing'); |
129
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'TailorEA') { |
130
|
0
|
|
|
|
|
0
|
carp "$k is obsoleted. Use EAWidth"; |
131
|
0
|
|
|
|
|
0
|
$ret = $self->_config('EAWidth'); |
132
|
0
|
0
|
|
|
|
0
|
if (! defined $ret) { |
133
|
0
|
|
|
|
|
0
|
return []; |
134
|
|
|
|
|
|
|
} else { |
135
|
0
|
|
|
|
|
0
|
return [map { ($_->[0] => $_->[1]) } @{$ret}]; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'TailorLB') { |
138
|
0
|
|
|
|
|
0
|
carp "$k is obsoleted. Use LBClass"; |
139
|
0
|
|
|
|
|
0
|
$ret = $self->_config('LBClass'); |
140
|
0
|
0
|
|
|
|
0
|
if (! defined $ret) { |
141
|
0
|
|
|
|
|
0
|
return []; |
142
|
|
|
|
|
|
|
} else { |
143
|
0
|
|
|
|
|
0
|
return [map { ($_->[0] => $_->[1]) } @{$ret}]; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'UrgentBreaking') { |
146
|
0
|
|
|
|
|
0
|
return $self->_config('Urgent'); |
147
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'UserBreaking') { |
148
|
0
|
|
|
|
|
0
|
carp "$k is obsoleted. Use Prep"; |
149
|
0
|
|
|
|
|
0
|
$ret = $self->_config('Prep'); |
150
|
0
|
0
|
|
|
|
0
|
if (! defined $ret) { |
151
|
0
|
|
|
|
|
0
|
return []; |
152
|
|
|
|
|
|
|
} else { |
153
|
0
|
|
|
|
|
0
|
return $ret; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} else { |
156
|
353
|
|
|
|
|
3151
|
return $self->_config($k); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# Set config. |
161
|
1045
|
|
|
|
|
1781
|
my @config = (); |
162
|
1045
|
|
|
|
|
2154
|
while (0 < scalar @_) { |
163
|
8237
|
|
|
|
|
11730
|
my $k = shift; |
164
|
8237
|
|
|
|
|
11308
|
my $v = shift; |
165
|
|
|
|
|
|
|
|
166
|
8237
|
50
|
|
|
|
30418
|
if (uc $k eq uc 'CharactersMax') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
167
|
0
|
|
|
|
|
0
|
push @config, 'CharMax' => $v; |
168
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'ColumnsMax') { |
169
|
10
|
|
|
|
|
26
|
push @config, 'ColMax' => $v; |
170
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'ColumnsMin') { |
171
|
0
|
|
|
|
|
0
|
push @config, 'ColMin' => $v; |
172
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'SizingMethod') { |
173
|
0
|
|
|
|
|
0
|
push @config, 'Sizing' => $v; |
174
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'TailorLB') { |
175
|
0
|
|
|
|
|
0
|
carp "$k is obsoleted. Use LBClass"; |
176
|
0
|
|
|
|
|
0
|
push @config, 'LBClass' => undef; |
177
|
0
|
0
|
|
|
|
0
|
if (! defined $v) { |
178
|
|
|
|
|
|
|
; |
179
|
|
|
|
|
|
|
} else { |
180
|
0
|
|
|
|
|
0
|
my @v = @{$v}; |
|
0
|
|
|
|
|
0
|
|
181
|
0
|
|
|
|
|
0
|
while (scalar(@v)) { |
182
|
0
|
|
|
|
|
0
|
my $k = shift @v; |
183
|
0
|
|
|
|
|
0
|
my $v = shift @v; |
184
|
0
|
|
|
|
|
0
|
push @config, 'LBClass' => [ $k => $v ]; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'TailorEA') { |
188
|
0
|
|
|
|
|
0
|
carp "$k is obsoleted. Use EAWidth"; |
189
|
0
|
|
|
|
|
0
|
push @config, 'EAWidth' => undef; |
190
|
0
|
0
|
|
|
|
0
|
if (! defined $v) { |
191
|
|
|
|
|
|
|
; |
192
|
|
|
|
|
|
|
} else { |
193
|
0
|
|
|
|
|
0
|
my @v = @{$v}; |
|
0
|
|
|
|
|
0
|
|
194
|
0
|
|
|
|
|
0
|
while (scalar(@v)) { |
195
|
0
|
|
|
|
|
0
|
my $k = shift @v; |
196
|
0
|
|
|
|
|
0
|
my $v = shift @v; |
197
|
0
|
|
|
|
|
0
|
push @config, 'EAWidth' => [ $k => $v ]; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'UserBreaking') { |
201
|
0
|
|
|
|
|
0
|
carp "$k is obsoleted. Use Prep"; |
202
|
0
|
|
|
|
|
0
|
push @config, 'Prep' => undef; |
203
|
0
|
0
|
|
|
|
0
|
if (! defined $v) { |
|
|
0
|
|
|
|
|
|
204
|
|
|
|
|
|
|
; |
205
|
|
|
|
|
|
|
} elsif (ref $v eq 'ARRAY') { |
206
|
0
|
|
|
|
|
0
|
push @config, map { ('Prep' => $_) } @{$v}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
207
|
|
|
|
|
|
|
} else { |
208
|
0
|
|
|
|
|
0
|
push @config, 'Prep' => $v; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
} elsif (uc $k eq uc 'UrgentBreaking') { |
211
|
0
|
|
|
|
|
0
|
push @config, 'Urgent' => $v; |
212
|
|
|
|
|
|
|
} else { |
213
|
8227
|
|
|
|
|
16795
|
push @config, $k => $v; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
1045
|
100
|
|
|
|
12999
|
$self->_config(@config) if scalar @config; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub context (@) { |
221
|
8
|
|
|
8
|
1
|
43
|
my %opts = @_; |
222
|
|
|
|
|
|
|
|
223
|
8
|
|
|
|
|
24
|
my $charset; |
224
|
|
|
|
|
|
|
my $language; |
225
|
8
|
|
|
|
|
0
|
my $context; |
226
|
8
|
|
|
|
|
32
|
foreach my $k (keys %opts) { |
227
|
16
|
100
|
|
|
|
275
|
if (uc $k eq 'CHARSET') { |
|
|
50
|
|
|
|
|
|
228
|
8
|
50
|
|
|
|
21
|
if (ref $opts{$k}) { |
229
|
0
|
|
|
|
|
0
|
$charset = $opts{$k}->as_string; |
230
|
|
|
|
|
|
|
} else { |
231
|
8
|
|
|
|
|
30
|
$charset = MIME::Charset->new($opts{$k})->as_string; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
} elsif (uc $k eq 'LANGUAGE') { |
234
|
8
|
|
|
|
|
17
|
$language = uc $opts{$k}; |
235
|
8
|
|
|
|
|
23
|
$language =~ s/_/-/; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
} |
238
|
8
|
50
|
33
|
|
|
556
|
if ($charset and $charset =~ /$EASTASIAN_CHARSETS/) { |
|
|
50
|
33
|
|
|
|
|
239
|
0
|
|
|
|
|
0
|
$context = 'EASTASIAN'; |
240
|
|
|
|
|
|
|
} elsif ($language and $language =~ /$EASTASIAN_LANGUAGES/) { |
241
|
0
|
|
|
|
|
0
|
$context = 'EASTASIAN'; |
242
|
|
|
|
|
|
|
} else { |
243
|
8
|
|
|
|
|
22
|
$context = 'NONEASTASIAN'; |
244
|
|
|
|
|
|
|
} |
245
|
8
|
|
|
|
|
52
|
$context; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
1; |