line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BibTeX::Parser::Author; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$BibTeX::Parser::Author::VERSION = '1.02'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
18
|
|
|
18
|
|
207719
|
use warnings; |
|
18
|
|
|
|
|
73
|
|
|
18
|
|
|
|
|
785
|
|
7
|
18
|
|
|
18
|
|
137
|
use strict; |
|
18
|
|
|
|
|
52
|
|
|
18
|
|
|
|
|
530
|
|
8
|
|
|
|
|
|
|
|
9
|
18
|
|
|
18
|
|
1181
|
use BibTeX::Parser; |
|
18
|
|
|
|
|
51
|
|
|
18
|
|
|
|
|
801
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use overload |
13
|
18
|
|
|
18
|
|
28230
|
'""' => \&to_string; |
|
18
|
|
|
|
|
24517
|
|
|
18
|
|
|
|
|
172
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
68
|
|
|
68
|
1
|
30833
|
my $class = shift; |
19
|
|
|
|
|
|
|
|
20
|
68
|
100
|
|
|
|
264
|
if (@_) { |
21
|
65
|
|
|
|
|
263
|
my $self = [ $class->split(@_) ]; |
22
|
65
|
|
|
|
|
489
|
return bless $self, $class; |
23
|
|
|
|
|
|
|
} else { |
24
|
3
|
|
|
|
|
11
|
return bless [], $class; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _get_or_set_field { |
29
|
406
|
|
|
406
|
|
1116
|
my ($self, $field, $value) = @_; |
30
|
406
|
100
|
|
|
|
1106
|
if (defined $value) { |
31
|
4
|
|
|
|
|
19
|
$self->[$field] = $value; |
32
|
|
|
|
|
|
|
} else { |
33
|
402
|
|
|
|
|
2205
|
return $self->[$field]; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub first { |
39
|
140
|
|
|
140
|
1
|
22652
|
shift->_get_or_set_field(0, @_); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub von { |
44
|
86
|
|
|
86
|
1
|
311
|
shift->_get_or_set_field(1, @_); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub last { |
49
|
94
|
|
|
94
|
1
|
950
|
shift->_get_or_set_field(2, @_); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub jr { |
54
|
86
|
|
|
86
|
1
|
328
|
shift->_get_or_set_field(3, @_); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Take a string and create an array [first, von, last, jr] |
59
|
|
|
|
|
|
|
sub split { |
60
|
98
|
|
|
98
|
1
|
19945
|
my ($self_or_class, $name) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# remove whitespace at start and end of string |
63
|
98
|
|
|
|
|
933
|
$name =~ s/^\s*(.*)\s*$/$1/s; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
98
|
100
|
|
|
|
437
|
if (!length($name)) { |
68
|
6
|
|
|
|
|
38
|
return (undef, undef, undef, undef); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
92
|
|
|
|
|
431
|
my @comma_separated = |
72
|
|
|
|
|
|
|
BibTeX::Parser::_split_braced_string($name, |
73
|
|
|
|
|
|
|
'\s*,\s*'); |
74
|
92
|
50
|
|
|
|
379
|
if (scalar(@comma_separated) == 0) { |
75
|
|
|
|
|
|
|
# Error? |
76
|
0
|
|
|
|
|
0
|
return (undef, undef, undef, undef); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
92
|
|
|
|
|
248
|
my $first=undef; |
80
|
92
|
|
|
|
|
198
|
my $von=undef; |
81
|
92
|
|
|
|
|
201
|
my $last=undef; |
82
|
92
|
|
|
|
|
194
|
my $jr=undef; |
83
|
|
|
|
|
|
|
|
84
|
92
|
100
|
|
|
|
278
|
if (scalar(@comma_separated) == 1) { |
85
|
|
|
|
|
|
|
# First von Last form |
86
|
65
|
|
|
|
|
290
|
my @tokens = |
87
|
|
|
|
|
|
|
BibTeX::Parser::_split_braced_string($name, '\s+'); |
88
|
65
|
50
|
|
|
|
244
|
if (!scalar (@tokens)) { |
89
|
0
|
|
|
|
|
0
|
return (undef, undef, undef, undef); |
90
|
|
|
|
|
|
|
} |
91
|
65
|
|
|
|
|
253
|
my ($start_von, $start_last) = _getStartVonLast (@tokens); |
92
|
65
|
100
|
|
|
|
239
|
if ($start_von >0) { |
93
|
55
|
|
|
|
|
296
|
$first = join(' ', splice(@tokens,0,$start_von)); |
94
|
|
|
|
|
|
|
} |
95
|
65
|
100
|
|
|
|
260
|
if (($start_last-$start_von) >0) { |
96
|
9
|
|
|
|
|
37
|
$von = join(' ', splice(@tokens,0,$start_last-$start_von)); |
97
|
|
|
|
|
|
|
} |
98
|
65
|
|
|
|
|
222
|
$last = join(' ',@tokens); |
99
|
65
|
|
|
|
|
542
|
return ($first, $von, $last, $jr); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
# Now we work with von Last, [Jr,] First form |
102
|
27
|
100
|
|
|
|
160
|
if (scalar @comma_separated == 2) { # no jr |
103
|
21
|
|
|
|
|
97
|
my @tokens= |
104
|
|
|
|
|
|
|
BibTeX::Parser::_split_braced_string($comma_separated[1], '\s+'); |
105
|
21
|
|
|
|
|
106
|
$first = join(' ', @tokens); |
106
|
|
|
|
|
|
|
} else { # jr is present |
107
|
6
|
|
|
|
|
33
|
my @tokens= |
108
|
|
|
|
|
|
|
BibTeX::Parser::_split_braced_string($comma_separated[1], '\s+'); |
109
|
6
|
|
|
|
|
25
|
$jr = join(' ', @tokens); |
110
|
6
|
|
|
|
|
31
|
@tokens= |
111
|
|
|
|
|
|
|
BibTeX::Parser::_split_braced_string($comma_separated[2], '\s+'); |
112
|
6
|
|
|
|
|
31
|
$first = join(' ', @tokens); |
113
|
|
|
|
|
|
|
} |
114
|
27
|
|
|
|
|
127
|
my @tokens = |
115
|
|
|
|
|
|
|
BibTeX::Parser::_split_braced_string($comma_separated[0], '\s+'); |
116
|
27
|
|
|
|
|
101
|
my $start_last = _getStartLast(@tokens); |
117
|
27
|
100
|
|
|
|
95
|
if ($start_last > 0) { |
118
|
10
|
|
|
|
|
87
|
$von=join(' ', splice(@tokens,0,$start_last)); |
119
|
|
|
|
|
|
|
} |
120
|
27
|
|
|
|
|
100
|
$last = join(' ',@tokens); |
121
|
27
|
|
|
|
|
276
|
return ($first, $von, $last, $jr); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Return the index of the first von element and the first lastname |
126
|
|
|
|
|
|
|
# element. If no von element, von=last |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _getStartVonLast { |
129
|
65
|
|
|
65
|
|
178
|
my $length=scalar(@_); |
130
|
65
|
100
|
|
|
|
229
|
if ($length==1) { |
131
|
8
|
|
|
|
|
59
|
return (0,0); |
132
|
|
|
|
|
|
|
} |
133
|
57
|
|
|
|
|
136
|
my $start_von=-1; |
134
|
57
|
|
|
|
|
160
|
my $start_last=$length-1; |
135
|
57
|
|
|
|
|
216
|
for (my $i=0; $i<$length; $i++) { |
136
|
130
|
100
|
|
|
|
401
|
if (_is_von_token($_[$i])) { |
137
|
14
|
|
|
|
|
34
|
$start_von=$i; |
138
|
14
|
|
|
|
|
32
|
last; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
57
|
100
|
|
|
|
186
|
if ($start_von== -1) { # no von part |
142
|
43
|
|
|
|
|
168
|
return($length-1, $length-1); |
143
|
|
|
|
|
|
|
} |
144
|
14
|
100
|
|
|
|
57
|
if ($start_von== $length-1) { # all parts but last are upper case? |
145
|
5
|
|
|
|
|
10
|
return($length-1, $length-1); |
146
|
|
|
|
|
|
|
} |
147
|
9
|
|
|
|
|
49
|
for (my $i=$start_von+1; $i<$length; $i++) { |
148
|
13
|
100
|
|
|
|
44
|
if (!_is_von_token($_[$i])) { |
149
|
9
|
|
|
|
|
26
|
$start_last=$i; |
150
|
9
|
|
|
|
|
23
|
last; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
9
|
|
|
|
|
36
|
return($start_von, $start_last); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# Return the index of the first lastname |
158
|
|
|
|
|
|
|
# element provided no first name elements are present |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub _getStartLast { |
161
|
27
|
|
|
27
|
|
74
|
my $length=scalar(@_); |
162
|
27
|
100
|
|
|
|
101
|
if ($length==1) { |
163
|
15
|
|
|
|
|
44
|
return 0; |
164
|
|
|
|
|
|
|
} |
165
|
12
|
|
|
|
|
40
|
my $start_last=$length-1; |
166
|
12
|
|
|
|
|
56
|
for (my $i=0; $i<$length; $i++) { |
167
|
22
|
100
|
|
|
|
132
|
if (!_is_von_token($_[$i])) { |
168
|
12
|
|
|
|
|
31
|
$start_last=$i; |
169
|
12
|
|
|
|
|
33
|
last; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
12
|
|
|
|
|
38
|
return $start_last; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub _split_name_parts { |
177
|
0
|
|
|
0
|
|
0
|
my $name = shift; |
178
|
|
|
|
|
|
|
|
179
|
0
|
0
|
|
|
|
0
|
if ( $name !~ /\{/ ) { |
180
|
0
|
|
|
|
|
0
|
return split /\s+/, $name; |
181
|
|
|
|
|
|
|
} else { |
182
|
0
|
|
|
|
|
0
|
my @parts; |
183
|
0
|
|
|
|
|
0
|
my $cur_token = ''; |
184
|
0
|
|
|
|
|
0
|
while ( scalar( $name =~ /\G ( [^\s\{]* ) ( \s+ | \{ | \s* $ ) /xgc ) ) { |
185
|
0
|
|
|
|
|
0
|
$cur_token .= $1; |
186
|
0
|
0
|
|
|
|
0
|
if ( $2 =~ /\{/ ) { |
187
|
0
|
0
|
|
|
|
0
|
if ( scalar( $name =~ /\G([^\}]*)\}/gc ) ) { |
188
|
0
|
|
|
|
|
0
|
$cur_token .= "{$1}"; |
189
|
|
|
|
|
|
|
} else { |
190
|
0
|
|
|
|
|
0
|
die "Unmatched brace in name '$name'"; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
} else { |
193
|
0
|
0
|
|
|
|
0
|
if ( $cur_token =~ /^{(.*)}$/ ) { |
194
|
0
|
|
|
|
|
0
|
$cur_token = $1; |
195
|
|
|
|
|
|
|
} |
196
|
0
|
|
|
|
|
0
|
push @parts, $cur_token; |
197
|
0
|
|
|
|
|
0
|
$cur_token = ''; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
} |
200
|
0
|
|
|
|
|
0
|
return @parts; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub _get_single_author_from_tokens { |
207
|
0
|
|
|
0
|
|
0
|
my (@tokens) = @_; |
208
|
0
|
0
|
|
|
|
0
|
if (@tokens == 0) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
209
|
0
|
|
|
|
|
0
|
return (undef, undef, undef, undef); |
210
|
|
|
|
|
|
|
} elsif (@tokens == 1) { # name without comma |
211
|
0
|
0
|
|
|
|
0
|
if ( $tokens[0] =~ /(^|\s)[[:lower:]]/) { # name has von part or has only lowercase names |
212
|
0
|
|
|
|
|
0
|
my @name_parts = _split_name_parts $tokens[0]; |
213
|
|
|
|
|
|
|
|
214
|
0
|
|
|
|
|
0
|
my $first; |
215
|
0
|
|
0
|
|
|
0
|
while (@name_parts && ucfirst($name_parts[0]) eq $name_parts[0] ) { |
216
|
0
|
0
|
|
|
|
0
|
$first .= $first ? ' ' . shift @name_parts : shift @name_parts; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
0
|
my $von; |
220
|
|
|
|
|
|
|
# von part are lowercase words |
221
|
0
|
|
0
|
|
|
0
|
while ( @name_parts && lc($name_parts[0]) eq $name_parts[0] ) { |
222
|
0
|
0
|
|
|
|
0
|
$von .= $von ? ' ' . shift @name_parts : shift @name_parts; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
0
|
0
|
|
|
|
0
|
if (@name_parts) { |
226
|
0
|
|
|
|
|
0
|
return ($first, $von, join(" ", @name_parts), undef); |
227
|
|
|
|
|
|
|
} else { |
228
|
0
|
|
|
|
|
0
|
return (undef, undef, $tokens[0], undef); |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
} else { |
231
|
0
|
0
|
0
|
|
|
0
|
if ( $tokens[0] !~ /\{/ && $tokens[0] =~ /^((.*)\s+)?\b(\S+)$/) { |
232
|
0
|
|
|
|
|
0
|
return ($2, undef, $3, undef); |
233
|
|
|
|
|
|
|
} else { |
234
|
0
|
|
|
|
|
0
|
my @name_parts = _split_name_parts $tokens[0]; |
235
|
0
|
|
|
|
|
0
|
return ($name_parts[0], undef, $name_parts[1], undef); |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
} elsif (@tokens == 2) { |
240
|
0
|
|
|
|
|
0
|
my @von_last_parts = _split_name_parts $tokens[0]; |
241
|
0
|
|
|
|
|
0
|
my $von; |
242
|
|
|
|
|
|
|
# von part are lowercase words |
243
|
0
|
|
0
|
|
|
0
|
while ( @von_last_parts && lc($von_last_parts[0]) eq $von_last_parts[0] ) { |
244
|
0
|
0
|
|
|
|
0
|
$von .= $von ? ' ' . shift @von_last_parts : shift @von_last_parts; |
245
|
|
|
|
|
|
|
} |
246
|
0
|
|
|
|
|
0
|
return ($tokens[1], $von, join(" ", @von_last_parts), undef); |
247
|
|
|
|
|
|
|
} else { |
248
|
0
|
|
|
|
|
0
|
my @von_last_parts = _split_name_parts $tokens[0]; |
249
|
0
|
|
|
|
|
0
|
my $von; |
250
|
|
|
|
|
|
|
# von part are lowercase words |
251
|
0
|
|
0
|
|
|
0
|
while ( @von_last_parts && lc($von_last_parts[0]) eq $von_last_parts[0] ) { |
252
|
0
|
0
|
|
|
|
0
|
$von .= $von ? ' ' . shift @von_last_parts : shift @von_last_parts; |
253
|
|
|
|
|
|
|
} |
254
|
0
|
|
|
|
|
0
|
return ($tokens[2], $von, join(" ", @von_last_parts), $tokens[1]); |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
sub to_string { |
263
|
46
|
|
|
46
|
1
|
2625
|
my $self = shift; |
264
|
|
|
|
|
|
|
|
265
|
46
|
50
|
|
|
|
138
|
if ($self->jr) { |
266
|
0
|
0
|
|
|
|
0
|
return ($self->von ? $self->von . " " : '') . " " . $self->last . ", " . $self->jr . ", " . $self->first; |
267
|
|
|
|
|
|
|
} else { |
268
|
46
|
50
|
|
|
|
127
|
return ($self->von ? $self->von . " " : '') . $self->last . ($self->first ? ", " . $self->first : ''); |
|
|
50
|
|
|
|
|
|
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
# Return 1 if the first letter on brace level 0 is lowercase |
274
|
|
|
|
|
|
|
sub _is_von_token { |
275
|
170
|
|
|
170
|
|
518
|
my $string = shift; |
276
|
170
|
|
|
|
|
875
|
while ($string =~ |
277
|
|
|
|
|
|
|
s/^(\\[[:alpha:]]+\{|\{|\\[[:^alpha:]]?|[[:^alpha:]])//) { |
278
|
8
|
100
|
|
|
|
59
|
if ($1 eq '{' ) { |
279
|
5
|
|
|
|
|
9
|
my $numbraces=1; |
280
|
5
|
|
66
|
|
|
21
|
while ($numbraces !=0 && length($string)) { |
281
|
66
|
|
|
|
|
125
|
my $symbol = substr($string, 0, 1); |
282
|
66
|
50
|
|
|
|
125
|
if ($symbol eq '{') { |
|
|
100
|
|
|
|
|
|
283
|
0
|
|
|
|
|
0
|
$numbraces ++; |
284
|
|
|
|
|
|
|
} elsif ($symbol eq '}') { |
285
|
5
|
|
|
|
|
10
|
$numbraces --; |
286
|
|
|
|
|
|
|
} |
287
|
66
|
|
|
|
|
175
|
$string = substr($string,1); |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
|
292
|
170
|
100
|
|
|
|
489
|
if (length $string ) { |
293
|
165
|
|
|
|
|
440
|
my $symbol = substr($string, 0, 1); |
294
|
165
|
100
|
|
|
|
504
|
if (lc($symbol) eq $symbol) { |
295
|
25
|
|
|
|
|
184
|
return 1; |
296
|
|
|
|
|
|
|
} else { |
297
|
140
|
|
|
|
|
642
|
return 0; |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
} else { |
300
|
5
|
|
|
|
|
11
|
return 1; |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
1; # End of BibTeX::Entry |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
__END__ |