line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Locale::Maketext::Lexicon::Getcontext; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
77506
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
49
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
945
|
use Locale::Maketext::Lexicon::Gettext; |
|
2
|
|
|
|
|
2445
|
|
|
2
|
|
|
|
|
196
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
8
|
|
|
|
|
|
|
my ( $InputEncoding, $OutputEncoding, $DoEncoding ); |
9
|
|
|
|
|
|
|
|
10
|
0
|
|
|
0
|
0
|
0
|
sub input_encoding {$InputEncoding} |
11
|
0
|
|
|
0
|
0
|
0
|
sub output_encoding {$OutputEncoding} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# functions |
14
|
|
|
|
|
|
|
*parse_mo = \&Locale::Maketext::Lexicon::Gettext::parse_mo; |
15
|
|
|
|
|
|
|
*_unescape = \&Locale::Maketext::Lexicon::Gettext::_unescape; |
16
|
|
|
|
|
|
|
*_gettext_to_maketext |
17
|
|
|
|
|
|
|
= \&Locale::Maketext::Lexicon::Gettext::_gettext_to_maketext; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# parse() |
23
|
|
|
|
|
|
|
# ----- |
24
|
|
|
|
|
|
|
# copy-pasted from Locale::Maketext::Lexicon::Gettext, with s/msgid/msgctxt/g |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
sub parse { |
27
|
4
|
|
|
4
|
0
|
8698
|
my $self = shift; |
28
|
4
|
|
|
|
|
7
|
my ( %var, $key, @ret ); |
29
|
0
|
|
|
|
|
0
|
my @metadata; |
30
|
0
|
|
|
|
|
0
|
my @comments; |
31
|
0
|
|
|
|
|
0
|
my @fuzzy; |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
4
|
$InputEncoding = $OutputEncoding = $DoEncoding = undef; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
1558
|
|
36
|
4
|
50
|
|
|
|
12
|
Carp::cluck "Undefined source called\n" unless defined $_[0]; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Check for magic string of MO files |
39
|
4
|
50
|
33
|
|
|
29
|
return parse_mo( join( '', @_ ) ) |
40
|
|
|
|
|
|
|
if ( $_[0] =~ /^\x95\x04\x12\xde/ or $_[0] =~ /^\xde\x12\x04\x95/ ); |
41
|
|
|
|
|
|
|
|
42
|
4
|
|
|
|
|
12
|
local $^W; # no 'uninitialized' warnings, please. |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
21
|
require Locale::Maketext::Lexicon; |
45
|
4
|
|
|
|
|
16
|
my $KeepFuzzy = Locale::Maketext::Lexicon::option('keep_fuzzy'); |
46
|
4
|
|
33
|
|
|
30
|
my $UseFuzzy = $KeepFuzzy |
47
|
|
|
|
|
|
|
|| Locale::Maketext::Lexicon::option('use_fuzzy'); |
48
|
4
|
|
|
|
|
19
|
my $AllowEmpty = Locale::Maketext::Lexicon::option('allow_empty'); |
49
|
|
|
|
|
|
|
my $process = sub { |
50
|
1735
|
50
|
33
|
1735
|
|
5178
|
if ( length( $var{msgstr} ) and ( $UseFuzzy or !$var{fuzzy} ) ) { |
|
|
0
|
33
|
|
|
|
|
51
|
1735
|
|
|
|
|
2297
|
push @ret, ( map transform($_), @var{ 'msgctxt', 'msgstr' } ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ($AllowEmpty) { |
54
|
0
|
|
|
|
|
0
|
push @ret, ( transform( $var{msgctxt} ), '' ); |
55
|
|
|
|
|
|
|
} |
56
|
1735
|
100
|
|
|
|
15688
|
if ( $var{msgctxt} eq '' ) { |
57
|
4
|
|
|
|
|
6
|
push @metadata, parse_metadata( $var{msgstr} ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
1731
|
|
|
|
|
1819
|
push @comments, $var{msgctxt}, $var{msgcomment}; |
61
|
|
|
|
|
|
|
} |
62
|
1735
|
0
|
33
|
|
|
2069
|
if ( $KeepFuzzy && $var{fuzzy} ) { |
63
|
0
|
|
|
|
|
0
|
push @fuzzy, $var{msgctxt}, 1; |
64
|
|
|
|
|
|
|
} |
65
|
1735
|
|
|
|
|
2940
|
%var = (); |
66
|
4
|
|
|
|
|
21
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Parse PO files |
69
|
4
|
|
|
|
|
7
|
foreach (@_) { |
70
|
7703
|
|
|
|
|
24803
|
s/[\015\012]*\z//; # fix CRLF issues |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
/^(msgctxt|msgid|msgstr) +"(.*)" *$/ |
73
|
|
|
|
|
|
|
? do { # leading strings |
74
|
5201
|
|
|
|
|
7221
|
$var{$1} = $2; |
75
|
5201
|
|
|
|
|
5088
|
$key = $1; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
/^"(.*)" *$/ |
80
|
|
|
|
|
|
|
? do { # continued strings |
81
|
767
|
|
|
|
|
1034
|
$var{$key} .= $1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
/^# (.*)$/ |
86
|
|
|
|
|
|
|
? do { # user comments |
87
|
0
|
|
|
|
|
0
|
$var{msgcomment} .= $1 . "\n"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
/^#, +(.*) *$/ |
92
|
|
|
|
|
|
|
? do { # control variables |
93
|
0
|
|
|
|
|
0
|
$var{$_} = 1 for split( /,\s+/, $1 ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
/^ *$/ && %var |
98
|
7703
|
50
|
33
|
|
|
19169
|
? do { # interpolate string escapes |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
99
|
1735
|
|
|
|
|
1859
|
$process->($_); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
: (); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# do not silently skip last entry |
108
|
4
|
50
|
|
|
|
45
|
$process->() if keys %var != 0; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
0
|
push @ret, map { transform($_) } @var{ 'msgctxt', 'msgstr' } |
111
|
4
|
50
|
|
|
|
10
|
if length $var{msgstr}; |
112
|
|
|
|
|
|
|
push @metadata, parse_metadata( $var{msgstr} ) |
113
|
4
|
50
|
|
|
|
20
|
if $var{msgctxt} eq ''; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
return wantarray |
116
|
4
|
50
|
|
|
|
1742
|
? ( { @metadata, @ret }, {@comments}, {@fuzzy} ) |
117
|
|
|
|
|
|
|
: ( { @metadata, @ret } ); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# |
123
|
|
|
|
|
|
|
# parse_metadata() |
124
|
|
|
|
|
|
|
# -------------- |
125
|
|
|
|
|
|
|
# copy-pasted from Locale::Maketext::Lexicon::Gettext, with no change, |
126
|
|
|
|
|
|
|
# because it accesses the $InputEncoding and $OutputEncoding vars |
127
|
|
|
|
|
|
|
# |
128
|
|
|
|
|
|
|
sub parse_metadata { |
129
|
|
|
|
|
|
|
return map { |
130
|
8
|
|
|
8
|
0
|
13
|
(/^([^\x00-\x1f\x80-\xff :=]+):\s*(.*)$/) |
131
|
|
|
|
|
|
|
? ( $1 eq 'Content-Type' ) |
132
|
32
|
100
|
|
|
|
278
|
? do { |
|
|
50
|
|
|
|
|
|
133
|
4
|
|
|
|
|
5
|
my $enc = $2; |
134
|
4
|
50
|
|
|
|
18
|
if ( $enc =~ /\bcharset=\s*([-\w]+)/i ) { |
135
|
4
|
|
50
|
|
|
12
|
$InputEncoding = $1 || ''; |
136
|
4
|
|
50
|
|
|
22
|
$OutputEncoding |
137
|
|
|
|
|
|
|
= Locale::Maketext::Lexicon::encoding() |
138
|
|
|
|
|
|
|
|| ''; |
139
|
4
|
50
|
|
|
|
49
|
$InputEncoding = 'utf8' |
140
|
|
|
|
|
|
|
if $InputEncoding =~ /^utf-?8$/i; |
141
|
4
|
50
|
|
|
|
8
|
$OutputEncoding = 'utf8' |
142
|
|
|
|
|
|
|
if $OutputEncoding =~ /^utf-?8$/i; |
143
|
4
|
50
|
33
|
|
|
8
|
if (Locale::Maketext::Lexicon::option('decode') |
|
|
|
33
|
|
|
|
|
144
|
|
|
|
|
|
|
and ( !$OutputEncoding |
145
|
|
|
|
|
|
|
or $InputEncoding ne $OutputEncoding ) |
146
|
|
|
|
|
|
|
) |
147
|
|
|
|
|
|
|
{ |
148
|
4
|
50
|
|
|
|
36
|
require Encode::compat if $] < 5.007001; |
149
|
4
|
|
|
|
|
15
|
require Encode; |
150
|
4
|
|
|
|
|
5
|
$DoEncoding = 1; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
4
|
|
|
|
|
8
|
( "__Content-Type", $enc ); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
: ( "__$1", $2 ) |
156
|
|
|
|
|
|
|
: (); |
157
|
|
|
|
|
|
|
} split( /\r*\n+\r*/, transform(pop) ); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# |
162
|
|
|
|
|
|
|
# transform() |
163
|
|
|
|
|
|
|
# --------- |
164
|
|
|
|
|
|
|
# copy-pasted from Locale::Maketext::Lexicon::Gettext, with no change, |
165
|
|
|
|
|
|
|
# because it accesses the $InputEncoding and $OutputEncoding vars |
166
|
|
|
|
|
|
|
# |
167
|
|
|
|
|
|
|
sub transform { |
168
|
3478
|
|
|
3478
|
0
|
10859
|
my $str = shift; |
169
|
|
|
|
|
|
|
|
170
|
3478
|
100
|
66
|
|
|
8204
|
if ( $DoEncoding and $InputEncoding ) { |
171
|
3466
|
50
|
|
|
|
5605
|
$str |
172
|
|
|
|
|
|
|
= ( $InputEncoding eq 'utf8' ) |
173
|
|
|
|
|
|
|
? Encode::decode_utf8($str) |
174
|
|
|
|
|
|
|
: Encode::decode( $InputEncoding, $str ); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
3478
|
|
|
|
|
32300
|
$str =~ s/\\([0x]..|c?.)/qq{"\\$1"}/eeg; |
|
959
|
|
|
|
|
32367
|
|
178
|
|
|
|
|
|
|
|
179
|
3478
|
50
|
66
|
|
|
8559
|
if ( $DoEncoding and $OutputEncoding ) { |
180
|
0
|
0
|
|
|
|
0
|
$str |
181
|
|
|
|
|
|
|
= ( $OutputEncoding eq 'utf8' ) |
182
|
|
|
|
|
|
|
? Encode::encode_utf8($str) |
183
|
|
|
|
|
|
|
: Encode::encode( $OutputEncoding, $str ); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
3478
|
|
|
|
|
4366
|
return _gettext_to_maketext($str); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
__PACKAGE__ |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
__END__ |