| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package BibTeX::Parser::Entry; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$BibTeX::Parser::Entry::VERSION = '1.04'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
|
|
6
|
18
|
|
|
18
|
|
137385
|
use warnings; |
|
|
18
|
|
|
|
|
51
|
|
|
|
18
|
|
|
|
|
617
|
|
|
7
|
18
|
|
|
18
|
|
94
|
use strict; |
|
|
18
|
|
|
|
|
42
|
|
|
|
18
|
|
|
|
|
346
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
18
|
|
|
18
|
|
918
|
use BibTeX::Parser; |
|
|
18
|
|
|
|
|
37
|
|
|
|
18
|
|
|
|
|
546
|
|
|
10
|
18
|
|
|
18
|
|
7212
|
use BibTeX::Parser::Author; |
|
|
18
|
|
|
|
|
46
|
|
|
|
18
|
|
|
|
|
8168
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
|
15
|
130
|
|
|
130
|
1
|
449064
|
my ($class, $type, $key, $parse_ok, $fieldsref) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
130
|
100
|
|
|
|
607
|
my %fields = defined $fieldsref ? %$fieldsref : (); |
|
18
|
130
|
|
|
|
|
233
|
my $i=0; |
|
19
|
130
|
|
|
|
|
394
|
foreach my $field (keys %fields) { |
|
20
|
93
|
50
|
|
|
|
277
|
if ($field !~ /^_/) { |
|
21
|
93
|
|
|
|
|
211
|
$fields{_fieldnums}->{$field}=$i; |
|
22
|
93
|
|
|
|
|
174
|
$i++; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
} |
|
25
|
130
|
100
|
|
|
|
367
|
if (defined $type) { |
|
26
|
93
|
|
|
|
|
222
|
$fields{_type} = uc($type); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
130
|
|
|
|
|
224
|
$fields{_key} = $key; |
|
29
|
130
|
|
|
|
|
208
|
$fields{_parse_ok} = $parse_ok; |
|
30
|
130
|
|
|
|
|
221
|
$fields{_raw} = ''; |
|
31
|
130
|
|
|
|
|
487
|
return bless \%fields, $class; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub parse_ok { |
|
37
|
51
|
|
|
51
|
1
|
4170
|
my $self = shift; |
|
38
|
51
|
100
|
|
|
|
134
|
if (@_) { |
|
39
|
34
|
|
|
|
|
74
|
$self->{_parse_ok} = shift; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
51
|
|
|
|
|
130
|
$self->{_parse_ok}; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub error { |
|
46
|
2
|
|
|
2
|
1
|
6
|
my $self = shift; |
|
47
|
2
|
50
|
|
|
|
7
|
if (@_) { |
|
48
|
2
|
|
|
|
|
9
|
$self->{_error} = shift; |
|
49
|
2
|
|
|
|
|
6
|
$self->parse_ok(0); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
2
|
50
|
|
|
|
4
|
return $self->parse_ok ? undef : $self->{_error}; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub type { |
|
56
|
65
|
100
|
|
65
|
1
|
782
|
if (scalar @_ == 1) { |
|
57
|
|
|
|
|
|
|
# get |
|
58
|
28
|
|
|
|
|
84
|
my $self = shift; |
|
59
|
28
|
|
|
|
|
111
|
return $self->{_type}; |
|
60
|
|
|
|
|
|
|
} else { |
|
61
|
|
|
|
|
|
|
# set |
|
62
|
37
|
|
|
|
|
92
|
my ($self, $newval) = @_; |
|
63
|
37
|
|
|
|
|
146
|
$self->{_type} = uc($newval); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub key { |
|
69
|
90
|
100
|
|
90
|
1
|
2280
|
if (scalar @_ == 1) { |
|
70
|
|
|
|
|
|
|
# get |
|
71
|
58
|
|
|
|
|
90
|
my $self = shift; |
|
72
|
58
|
|
|
|
|
597
|
return $self->{_key}; |
|
73
|
|
|
|
|
|
|
} else { |
|
74
|
|
|
|
|
|
|
# set |
|
75
|
32
|
|
|
|
|
110
|
my ($self, $newval) = @_; |
|
76
|
32
|
|
|
|
|
95
|
$self->{_key} = $newval; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub field { |
|
83
|
332
|
100
|
|
332
|
1
|
686
|
if (scalar @_ == 2) { |
|
84
|
|
|
|
|
|
|
# get |
|
85
|
195
|
|
|
|
|
371
|
my ($self, $field) = @_; |
|
86
|
195
|
|
|
|
|
719
|
return $self->{ lc( $field ) }; |
|
87
|
|
|
|
|
|
|
} else { |
|
88
|
137
|
|
|
|
|
389
|
my ($self, $key, $value) = @_; |
|
89
|
137
|
|
|
|
|
262
|
my $field = lc ($key); |
|
90
|
137
|
|
|
|
|
332
|
$self->{$field} = $value; #_sanitize_field($value); |
|
91
|
137
|
100
|
|
|
|
329
|
if (!exists($self->{_fieldnums}->{$field})) { |
|
92
|
136
|
|
|
|
|
168
|
my $num = scalar keys %{$self->{_fieldnums}}; |
|
|
136
|
|
|
|
|
291
|
|
|
93
|
136
|
|
|
|
|
347
|
$self->{_fieldnums}->{$field} = $num; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
18
|
|
|
18
|
|
9674
|
use LaTeX::ToUnicode qw( convert ); |
|
|
18
|
|
|
|
|
306002
|
|
|
|
18
|
|
|
|
|
5623
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub cleaned_field { |
|
103
|
91
|
|
|
91
|
1
|
202
|
my ( $self, $field, @options ) = @_; |
|
104
|
91
|
50
|
|
|
|
199
|
if ( $field =~ /author|editor/i ) { |
|
105
|
0
|
|
|
|
|
0
|
return $self->field( $field ); |
|
106
|
|
|
|
|
|
|
} else { |
|
107
|
91
|
|
|
|
|
277
|
return convert( $self->field( lc $field ), @options ); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub cleaned_author { |
|
113
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
|
114
|
1
|
|
|
|
|
5
|
$self->_handle_cleaned_author_editor( [ $self->author ], @_ ); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub cleaned_editor { |
|
119
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
120
|
0
|
|
|
|
|
0
|
$self->_handle_cleaned_author_editor( [ $self->editor ], @_ ); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _handle_cleaned_author_editor { |
|
124
|
1
|
|
|
1
|
|
3
|
my ( $self, $authors, @options ) = @_; |
|
125
|
|
|
|
|
|
|
map { |
|
126
|
1
|
|
|
|
|
3
|
my $author = $_; |
|
|
2
|
|
|
|
|
24
|
|
|
127
|
2
|
|
|
|
|
28
|
my $new_author = BibTeX::Parser::Author->new; |
|
128
|
|
|
|
|
|
|
map { |
|
129
|
4
|
|
|
|
|
13
|
$new_author->$_( convert( $author->$_, @options ) ) |
|
130
|
2
|
|
|
|
|
5
|
} grep { defined $author->$_ } qw( first von last jr ); |
|
|
8
|
|
|
|
|
32
|
|
|
131
|
2
|
|
|
|
|
9
|
$new_author; |
|
132
|
|
|
|
|
|
|
} @$authors; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
18
|
|
|
18
|
|
171
|
no LaTeX::ToUnicode; |
|
|
18
|
|
|
|
|
40
|
|
|
|
18
|
|
|
|
|
20572
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _handle_author_editor { |
|
138
|
33
|
|
|
33
|
|
83
|
my $type = shift; |
|
139
|
33
|
|
|
|
|
57
|
my $self = shift; |
|
140
|
33
|
50
|
|
|
|
82
|
if (@_) { |
|
141
|
0
|
0
|
|
|
|
0
|
if (@_ == 1) { #single string |
|
142
|
|
|
|
|
|
|
# my @names = split /\s+and\s+/i, $_[0]; |
|
143
|
0
|
|
|
|
|
0
|
$_[0] =~ s/^\s*//; |
|
144
|
0
|
|
|
|
|
0
|
$_[0] =~ s/\s*$//; |
|
145
|
0
|
|
|
|
|
0
|
my @names = BibTeX::Parser::_split_braced_string($_[0], |
|
146
|
|
|
|
|
|
|
'\s+and\s+'); |
|
147
|
0
|
0
|
|
|
|
0
|
if (!scalar @names) { |
|
148
|
0
|
|
|
|
|
0
|
$self->error('Bad names in author/editor field'); |
|
149
|
0
|
|
|
|
|
0
|
return; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
0
|
|
|
|
|
0
|
$self->{"_$type"} = [map {new BibTeX::Parser::Author $_} @names]; |
|
|
0
|
|
|
|
|
0
|
|
|
152
|
0
|
|
|
|
|
0
|
$self->field($type, join " and ", @{$self->{"_$type"}}); |
|
|
0
|
|
|
|
|
0
|
|
|
153
|
|
|
|
|
|
|
} else { |
|
154
|
0
|
|
|
|
|
0
|
$self->{"_$type"} = []; |
|
155
|
0
|
|
|
|
|
0
|
foreach my $param (@_) { |
|
156
|
0
|
0
|
|
|
|
0
|
if (ref $param eq "BibTeX::Author") { |
|
157
|
0
|
|
|
|
|
0
|
push @{$self->{"_$type"}}, $param; |
|
|
0
|
|
|
|
|
0
|
|
|
158
|
|
|
|
|
|
|
} else { |
|
159
|
0
|
|
|
|
|
0
|
push @{$self->{"_$type"}}, new BibTeX::Parser::Author $param; |
|
|
0
|
|
|
|
|
0
|
|
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
0
|
$self->field($type, join " and ", @{$self->{"_$type"}}); |
|
|
0
|
|
|
|
|
0
|
|
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
} else { |
|
166
|
33
|
100
|
|
|
|
115
|
unless ( defined $self->{"_$type"}) { |
|
167
|
17
|
|
100
|
|
|
103
|
my @names = BibTeX::Parser::_split_braced_string($self->{$type} || "", '\s+and\s+' ); |
|
168
|
17
|
|
|
|
|
55
|
$self->{"_$type"} = [map {new BibTeX::Parser::Author $_} @names]; |
|
|
32
|
|
|
|
|
138
|
|
|
169
|
|
|
|
|
|
|
} |
|
170
|
33
|
|
|
|
|
61
|
return @{$self->{"_$type"}}; |
|
|
33
|
|
|
|
|
134
|
|
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub author { |
|
177
|
24
|
|
|
24
|
1
|
1402
|
_handle_author_editor('author', @_); |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub editor { |
|
182
|
9
|
|
|
9
|
1
|
542
|
_handle_author_editor('editor', @_); |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub fieldlist { |
|
187
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
|
188
|
|
|
|
|
|
|
|
|
189
|
1
|
|
|
|
|
4
|
return grep {!/^_/} keys %$self; |
|
|
7
|
|
|
|
|
23
|
|
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub has { |
|
194
|
3
|
|
|
3
|
1
|
8
|
my ($self, $field) = @_; |
|
195
|
|
|
|
|
|
|
|
|
196
|
3
|
|
|
|
|
17
|
return defined $self->{$field}; |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub _sanitize_field { |
|
200
|
0
|
|
|
0
|
|
0
|
my $value = shift; |
|
201
|
0
|
|
|
|
|
0
|
for ($value) { |
|
202
|
0
|
|
|
|
|
0
|
tr/\{\}//d; |
|
203
|
0
|
|
|
|
|
0
|
s/\\(?!=[ \\])//g; |
|
204
|
0
|
|
|
|
|
0
|
s/\\\\/\\/g; |
|
205
|
|
|
|
|
|
|
} |
|
206
|
0
|
|
|
|
|
0
|
return $value; |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub raw_bibtex { |
|
212
|
36
|
|
|
36
|
1
|
51
|
my $self = shift; |
|
213
|
36
|
50
|
|
|
|
97
|
if (@_) { |
|
214
|
36
|
|
|
|
|
78
|
$self->{_raw} = shift; |
|
215
|
|
|
|
|
|
|
} |
|
216
|
36
|
|
|
|
|
73
|
return $self->{_raw}; |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub pre { |
|
220
|
39
|
|
|
39
|
1
|
81
|
my $self = shift; |
|
221
|
39
|
100
|
|
|
|
95
|
if (@_) { |
|
222
|
36
|
|
|
|
|
84
|
$self->{_pre} = shift; |
|
223
|
|
|
|
|
|
|
} |
|
224
|
39
|
|
|
|
|
79
|
return $self->{_pre}; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub to_string { |
|
229
|
15
|
|
|
15
|
1
|
71
|
my $self = shift; |
|
230
|
15
|
|
|
|
|
38
|
my %options=@_; |
|
231
|
15
|
100
|
|
|
|
47
|
if (!exists($options{canonize_names})) { |
|
232
|
14
|
|
|
|
|
30
|
$options{canonize_names}=1; |
|
233
|
|
|
|
|
|
|
} |
|
234
|
15
|
|
|
|
|
68
|
my @fields = grep {!/^_/} keys %$self; |
|
|
180
|
|
|
|
|
398
|
|
|
235
|
|
|
|
|
|
|
@fields = sort { |
|
236
|
15
|
|
|
|
|
129
|
$self->{_fieldnums}->{$a} <=> |
|
237
|
113
|
|
|
|
|
198
|
$self->{_fieldnums}->{$b}} @fields; |
|
238
|
15
|
|
|
|
|
24
|
my $result = ''; |
|
239
|
15
|
100
|
|
|
|
36
|
if ($options{print_pre}) { |
|
240
|
3
|
|
|
|
|
8
|
$result .= $self->pre()."\n"; |
|
241
|
|
|
|
|
|
|
} |
|
242
|
15
|
|
|
|
|
67
|
my $type = $self->type; |
|
243
|
15
|
100
|
|
|
|
40
|
if (exists($options{type_capitalization})) { |
|
244
|
3
|
100
|
|
|
|
8
|
if ($options{type_capitalization} eq 'Lowercase') { |
|
245
|
1
|
|
|
|
|
3
|
$type = lc $type; |
|
246
|
|
|
|
|
|
|
} |
|
247
|
3
|
100
|
|
|
|
7
|
if ($options{type_capitalization} eq 'Titlecase') { |
|
248
|
1
|
|
|
|
|
4
|
$type = ucfirst lc $type; |
|
249
|
|
|
|
|
|
|
} |
|
250
|
|
|
|
|
|
|
} |
|
251
|
15
|
|
|
|
|
49
|
print STDERR $self->key, "\n"; |
|
252
|
15
|
|
|
|
|
94
|
$result .= '@'.$type."{".$self->key.",\n"; |
|
253
|
15
|
|
|
|
|
37
|
foreach my $field (@fields) { |
|
254
|
73
|
|
|
|
|
133
|
my $value = $self->field($field); |
|
255
|
73
|
100
|
100
|
|
|
198
|
if ($field eq 'author' && $options{canonize_names}) { |
|
256
|
14
|
|
|
|
|
38
|
my @names = ($self->author); |
|
257
|
14
|
|
|
|
|
121
|
$value = join(' and ', @names); |
|
258
|
|
|
|
|
|
|
} |
|
259
|
73
|
100
|
100
|
|
|
160
|
if ($field eq 'editor' && $options{canonize_names}) { |
|
260
|
8
|
|
|
|
|
17
|
my @names = ($self->editor); |
|
261
|
8
|
|
|
|
|
24
|
$value = join(' and ', @names); |
|
262
|
|
|
|
|
|
|
} |
|
263
|
73
|
100
|
|
|
|
137
|
if (exists($options{field_capitalization})) { |
|
264
|
15
|
100
|
|
|
|
28
|
if ($options{field_capitalization} eq 'Uppercase') { |
|
265
|
5
|
|
|
|
|
10
|
$field = uc $field; |
|
266
|
|
|
|
|
|
|
} |
|
267
|
15
|
100
|
|
|
|
29
|
if ($options{field_capitalization} eq 'Titlecase') { |
|
268
|
5
|
|
|
|
|
10
|
$field = ucfirst $field; |
|
269
|
|
|
|
|
|
|
} |
|
270
|
|
|
|
|
|
|
} |
|
271
|
73
|
|
|
|
|
211
|
$result .= " $field = {"."$value"."},\n"; |
|
272
|
|
|
|
|
|
|
} |
|
273
|
15
|
|
|
|
|
26
|
$result .= "}"; |
|
274
|
15
|
|
|
|
|
90
|
return $result; |
|
275
|
|
|
|
|
|
|
} |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
1; # End of BibTeX::Entry |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
__END__ |