| 1 | package BibTeX::Parser::Author; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 20 | $BibTeX::Parser::Author::VERSION = '1.95'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 20 | require BibTeX::Parser; # mutual dependency | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | use overload | ||||||||||||||||||||||||||||
| 11 | 20 | ▶ | '""' => \&to_string; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 72 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 72 | my $class = shift; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 72 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 69 | my $self = [ $class->split(@_) ]; | |||||||||||||||||||||||||||
| 20 | 69 | return bless $self, $class; | |||||||||||||||||||||||||||
| 21 | } else { | ||||||||||||||||||||||||||||
| 22 | 3 | return bless [], $class; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 426 | ▶ | sub _get_or_set_field { | ||||||||||||||||||||||||||
|
Subroutine
_get_or_set_field: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 27 | 426 | my ($self, $field, $value) = @_; | |||||||||||||||||||||||||||
| 28 | 426 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 4 | $self->[$field] = $value; | |||||||||||||||||||||||||||
| 30 | } else { | ||||||||||||||||||||||||||||
| 31 | 422 | return $self->[$field]; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 148 | ▶ | sub first { | ||||||||||||||||||||||||||
|
Subroutine
first: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 148 | shift->_get_or_set_field(0, @_); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 90 | ▶ | sub von { | ||||||||||||||||||||||||||
|
Subroutine
von: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 90 | shift->_get_or_set_field(1, @_); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 98 | ▶ | sub last { | ||||||||||||||||||||||||||
|
Subroutine
last: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 98 | shift->_get_or_set_field(2, @_); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 90 | ▶ | sub jr { | ||||||||||||||||||||||||||
|
Subroutine
jr: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 90 | shift->_get_or_set_field(3, @_); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # Take a string and create an array [first, von, last, jr] | ||||||||||||||||||||||||||||
| 57 | 102 | ▶ | sub split { | ||||||||||||||||||||||||||
|
Subroutine
split: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 102 | my ($self_or_class, $name) = @_; | |||||||||||||||||||||||||||
| 59 | #warn " starting split for $name\n"; | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # remove whitespace at start and end of string | ||||||||||||||||||||||||||||
| 62 | 102 | $name =~ s/^\s*(.*)\s*$/$1/s; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 102 | ▶ | if (!length($name)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 6 | return (undef, undef, undef, undef); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 96 | my @comma_separated = | |||||||||||||||||||||||||||
| 71 | BibTeX::Parser::_split_braced_string($name, | ||||||||||||||||||||||||||||
| 72 | '\s*,\s*'); | ||||||||||||||||||||||||||||
| 73 | #warn " got ccs (", 0+@comma_separated, "): @comma_separated\n"; | ||||||||||||||||||||||||||||
| 74 | 96 | ▶ | if (scalar(@comma_separated) == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | # Error? | ||||||||||||||||||||||||||||
| 76 | 0 | return (undef, undef, undef, undef); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 96 | my $first=undef; | |||||||||||||||||||||||||||
| 80 | 96 | my $von=undef; | |||||||||||||||||||||||||||
| 81 | 96 | my $last=undef; | |||||||||||||||||||||||||||
| 82 | 96 | my $jr=undef; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 96 | ▶ | if (scalar(@comma_separated) == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | # First von Last form | ||||||||||||||||||||||||||||
| 86 | 69 | my @tokens = | |||||||||||||||||||||||||||
| 87 | BibTeX::Parser::_split_braced_string($name, '\s+'); | ||||||||||||||||||||||||||||
| 88 | 69 | ▶ | if (!scalar (@tokens)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | return (undef, undef, undef, undef); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 69 | my ($start_von, $start_last) = _getStartVonLast (@tokens); | |||||||||||||||||||||||||||
| 92 | #warn " got start_von=$start_von, start_last=$start_last for tokens @tokens\n"; | ||||||||||||||||||||||||||||
| 93 | 69 | ▶ | if ($start_von >0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 59 | $first = join(' ', splice(@tokens,0,$start_von)); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 69 | ▶ | if (($start_last-$start_von) >0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 9 | $von = join(' ', splice(@tokens,0,$start_last-$start_von)); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 69 | $last = join(' ',@tokens); | |||||||||||||||||||||||||||
| 100 | 69 | return ($first, $von, $last, $jr); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | # Now we work with von Last, [Jr,] First form | ||||||||||||||||||||||||||||
| 103 | 27 | ▶ | if (scalar @comma_separated == 2) { # no jr | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 21 | my @tokens= | |||||||||||||||||||||||||||
| 105 | BibTeX::Parser::_split_braced_string($comma_separated[1], '\s+'); | ||||||||||||||||||||||||||||
| 106 | 21 | $first = join(' ', @tokens); | |||||||||||||||||||||||||||
| 107 | } else { # jr is present | ||||||||||||||||||||||||||||
| 108 | 6 | my @tokens= | |||||||||||||||||||||||||||
| 109 | BibTeX::Parser::_split_braced_string($comma_separated[1], '\s+'); | ||||||||||||||||||||||||||||
| 110 | 6 | $jr = join(' ', @tokens); | |||||||||||||||||||||||||||
| 111 | 6 | @tokens= | |||||||||||||||||||||||||||
| 112 | BibTeX::Parser::_split_braced_string($comma_separated[2], '\s+'); | ||||||||||||||||||||||||||||
| 113 | 6 | $first = join(' ', @tokens); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 27 | my @tokens = | |||||||||||||||||||||||||||
| 116 | BibTeX::Parser::_split_braced_string($comma_separated[0], '\s+'); | ||||||||||||||||||||||||||||
| 117 | 27 | my $start_last = _getStartLast(@tokens); | |||||||||||||||||||||||||||
| 118 | 27 | ▶ | if ($start_last > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 10 | $von=join(' ', splice(@tokens,0,$start_last)); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 27 | $last = join(' ',@tokens); | |||||||||||||||||||||||||||
| 122 | 27 | return ($first, $von, $last, $jr); | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # Return the index of the first von element and the first lastname | ||||||||||||||||||||||||||||
| 127 | # element. If no von element, von=last | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 69 | ▶ | sub _getStartVonLast { | ||||||||||||||||||||||||||
|
Subroutine
_getStartVonLast: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 130 | 69 | my $length=scalar(@_); | |||||||||||||||||||||||||||
| 131 | 69 | ▶ | if ($length==1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 8 | return (0,0); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 61 | my $start_von=-1; | |||||||||||||||||||||||||||
| 135 | 61 | my $start_last=$length-1; | |||||||||||||||||||||||||||
| 136 | 61 | ▶ | for (my $i=0; $i<$length; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 138 | ▶ | if (_is_von_token($_[$i])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 14 | $start_von=$i; | |||||||||||||||||||||||||||
| 139 | 14 | last; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | 61 | ▶ | if ($start_von== -1) { # no von part | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 47 | return($length-1, $length-1); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | 14 | ▶ | if ($start_von== $length-1) { # all parts but last are upper case? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 5 | return($length-1, $length-1); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 9 | ▶ | for (my $i=$start_von+1; $i<$length; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 13 | ▶ | if (!_is_von_token($_[$i])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 9 | $start_last=$i; | |||||||||||||||||||||||||||
| 151 | 9 | last; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | 9 | return($start_von, $start_last); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # Return the index of the first lastname | ||||||||||||||||||||||||||||
| 159 | # element provided no first name elements are present | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 27 | ▶ | sub _getStartLast { | ||||||||||||||||||||||||||
|
Subroutine
_getStartLast: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 162 | 27 | my $length=scalar(@_); | |||||||||||||||||||||||||||
| 163 | 27 | ▶ | if ($length==1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 15 | return 0; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | 12 | my $start_last=$length-1; | |||||||||||||||||||||||||||
| 167 | 12 | ▶ | for (my $i=0; $i<$length; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 22 | ▶ | if (!_is_von_token($_[$i])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 12 | $start_last=$i; | |||||||||||||||||||||||||||
| 170 | 12 | last; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | 12 | return $start_last; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub _split_name_parts { | ||||||||||||||||||||||||||
|
Subroutine
_split_name_parts: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 178 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if ( $name !~ /\{/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 0 | return split /\s+/, $name; | |||||||||||||||||||||||||||
| 182 | } else { | ||||||||||||||||||||||||||||
| 183 | 0 | my @parts; | |||||||||||||||||||||||||||
| 184 | 0 | my $cur_token = ''; | |||||||||||||||||||||||||||
| 185 | 0 | ▶ | while ( scalar( $name =~ /\G ( [^\s\{]* ) ( \s+ | \{ | \s* $ ) /xgc ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | $cur_token .= $1; | |||||||||||||||||||||||||||
| 187 | 0 | ▶ | if ( $2 =~ /\{/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if ( scalar( $name =~ /\G([^\}]*)\}/gc ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 0 | $cur_token .= "{$1}"; | |||||||||||||||||||||||||||
| 190 | } else { | ||||||||||||||||||||||||||||
| 191 | 0 | die "Unmatched brace in name '$name'"; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | } else { | ||||||||||||||||||||||||||||
| 194 | 0 | ▶ | if ( $cur_token =~ /^{(.*)}$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 0 | $cur_token = $1; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | 0 | push @parts, $cur_token; | |||||||||||||||||||||||||||
| 198 | 0 | $cur_token = ''; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | 0 | return @parts; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | ▶ | sub _get_single_author_from_tokens { | ||||||||||||||||||||||||||
|
Subroutine
_get_single_author_from_tokens: not called CC=20 SCAR=60.4
| |||||||||||||||||||||||||||||
| 208 | 0 | my (@tokens) = @_; | |||||||||||||||||||||||||||
| 209 | 0 | ▶ | if (@tokens == 0) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 210 | 0 | return (undef, undef, undef, undef); | |||||||||||||||||||||||||||
| 211 | } elsif (@tokens == 1) { # name without comma | ||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if ( $tokens[0] =~ /(^|\s)[[:lower:]]/) { # name has von part or has only lowercase names | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 0 | my @name_parts = _split_name_parts $tokens[0]; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | my $first; | |||||||||||||||||||||||||||
| 216 | 0 | ▶ | while (@name_parts && ucfirst($name_parts[0]) eq $name_parts[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@name_parts and ucfirst $name_parts[0] eq $name_parts[0]
MC/DC0%0/2
@name_parts and ucfirst $name_parts[0] eq $name_parts[0]
@name_parts
ucfirst $name_parts[0] eq $name_parts[0]
Truth table0%0/3
A and B
A= @name_partsB= ucfirst $name_parts[0] eq $name_parts[0]
| |||||||||||||||||||||||||||||
| 217 | 0 | ▶ | $first .= $first ? ' ' . shift @name_parts : shift @name_parts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 0 | my $von; | |||||||||||||||||||||||||||
| 221 | # von part are lowercase words | ||||||||||||||||||||||||||||
| 222 | 0 | ▶ | while ( @name_parts && lc($name_parts[0]) eq $name_parts[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@name_parts and lc $name_parts[0] eq $name_parts[0]
MC/DC0%0/2
@name_parts and lc $name_parts[0] eq $name_parts[0]
@name_parts
lc $name_parts[0] eq $name_parts[0]
Truth table0%0/3
A and B
A= @name_partsB= lc $name_parts[0] eq $name_parts[0]
| |||||||||||||||||||||||||||||
| 223 | 0 | ▶ | $von .= $von ? ' ' . shift @name_parts : shift @name_parts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if (@name_parts) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 0 | return ($first, $von, join(" ", @name_parts), undef); | |||||||||||||||||||||||||||
| 228 | } else { | ||||||||||||||||||||||||||||
| 229 | 0 | return (undef, undef, $tokens[0], undef); | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | } else { | ||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if ( $tokens[0] !~ /\{/ && $tokens[0] =~ /^((.*)\s+)?\b(\S+)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $tokens[0] =~ /\{/ and $tokens[0] =~ /^((.*)\s+)?\b(\S+)$/
MC/DC0%0/2
not $tokens[0] =~ /\{/ and $tokens[0] =~ /^((.*)\s+)?\b(\S+)$/
not $tokens[0] =~ /\{/
$tokens[0] =~ /^((.*)\s+)?\b(\S+)$/
Truth table0%0/3
not(A) and B
A= not $tokens[0] =~ /\{/B= $tokens[0] =~ /^((.*)\s+)?\b(\S+)$/
| |||||||||||||||||||||||||||||
| 233 | 0 | return ($2, undef, $3, undef); | |||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||
| 235 | 0 | my @name_parts = _split_name_parts $tokens[0]; | |||||||||||||||||||||||||||
| 236 | 0 | return ($name_parts[0], undef, $name_parts[1], undef); | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | } elsif (@tokens == 2) { | ||||||||||||||||||||||||||||
| 241 | 0 | my @von_last_parts = _split_name_parts $tokens[0]; | |||||||||||||||||||||||||||
| 242 | 0 | my $von; | |||||||||||||||||||||||||||
| 243 | # von part are lowercase words | ||||||||||||||||||||||||||||
| 244 | 0 | ▶ | while ( @von_last_parts && lc($von_last_parts[0]) eq $von_last_parts[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@von_last_parts and lc $von_last_parts[0] eq $von_last_parts[0]
MC/DC0%0/2
@von_last_parts and lc $von_last_parts[0] eq $von_last_parts[0]
@von_last_parts
lc $von_last_parts[0] eq $von_last_parts[0]
Truth table0%0/3
A and B
A= @von_last_partsB= lc $von_last_parts[0] eq $von_last_parts[0]
| |||||||||||||||||||||||||||||
| 245 | 0 | ▶ | $von .= $von ? ' ' . shift @von_last_parts : shift @von_last_parts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | 0 | return ($tokens[1], $von, join(" ", @von_last_parts), undef); | |||||||||||||||||||||||||||
| 248 | } else { | ||||||||||||||||||||||||||||
| 249 | 0 | my @von_last_parts = _split_name_parts $tokens[0]; | |||||||||||||||||||||||||||
| 250 | 0 | my $von; | |||||||||||||||||||||||||||
| 251 | # von part are lowercase words | ||||||||||||||||||||||||||||
| 252 | 0 | ▶ | while ( @von_last_parts && lc($von_last_parts[0]) eq $von_last_parts[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@von_last_parts and lc $von_last_parts[0] eq $von_last_parts[0]
MC/DC0%0/2
@von_last_parts and lc $von_last_parts[0] eq $von_last_parts[0]
@von_last_parts
lc $von_last_parts[0] eq $von_last_parts[0]
Truth table0%0/3
A and B
A= @von_last_partsB= lc $von_last_parts[0] eq $von_last_parts[0]
| |||||||||||||||||||||||||||||
| 253 | 0 | ▶ | $von .= $von ? ' ' . shift @von_last_parts : shift @von_last_parts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | 0 | return ($tokens[2], $von, join(" ", @von_last_parts), $tokens[1]); | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | # The goal is to return a name in form | ||||||||||||||||||||||||||||
| 263 | # von Last, Jr, First | ||||||||||||||||||||||||||||
| 264 | # where any of the parts except Last may be empty. | ||||||||||||||||||||||||||||
| 265 | # | ||||||||||||||||||||||||||||
| 266 | 50 | ▶ | sub to_string { | ||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||
| 267 | 50 | my $self = shift; | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 50 | my $last = $self->last; # assume always present | |||||||||||||||||||||||||||
| 270 | 50 | ▶ | my $first = $self->first ? (", " . $self->first) : ''; # ", first" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | 50 | ▶ | my $von = $self->von ? ($self->von . " ") : ''; # "von " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 50 | ▶ | my $jr = $self->jr ? (", " . $self->jr ) : ''; # ", jr" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | # | ||||||||||||||||||||||||||||
| 274 | 50 | my $ret = "${von}${last}${jr}${first}"; | |||||||||||||||||||||||||||
| 275 | #warn "returning name: $ret\n"; | ||||||||||||||||||||||||||||
| 276 | 50 | return $ret; | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | # original code, which introduced a spurious space with a von part. | ||||||||||||||||||||||||||||
| 279 | # https://github.com/borisveytsman/crossrefware/issues/11 | ||||||||||||||||||||||||||||
| 280 | # | ||||||||||||||||||||||||||||
| 281 | # if ($self->jr) { | ||||||||||||||||||||||||||||
| 282 | # return () . " " . $self->last . ", " . $self->jr . ", " . $self->first; | ||||||||||||||||||||||||||||
| 283 | # } else { | ||||||||||||||||||||||||||||
| 284 | # return ($self->von ? $self->von . " " : '') . $self->last . ($self->first ? ", " . $self->first : ''); | ||||||||||||||||||||||||||||
| 285 | # } | ||||||||||||||||||||||||||||
| 286 | # | ||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | # Return 1 if the first letter on brace level 0 is lowercase | ||||||||||||||||||||||||||||
| 291 | 178 | ▶ | sub _is_von_token { | ||||||||||||||||||||||||||
|
Subroutine
_is_von_token: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||
| 292 | 178 | my $string = shift; | |||||||||||||||||||||||||||
| 293 | #warn " checking von: $string\n"; | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | # The while loop removes all non-alpha characters from the front of | ||||||||||||||||||||||||||||
| 296 | # the string. But our input might use an entity for a character, | ||||||||||||||||||||||||||||
| 297 | # say Šimon for \v{S}imon. If we go through the loop, we will | ||||||||||||||||||||||||||||
| 298 | # wrongly consider the "x" of "&#x" to be the first character, and | ||||||||||||||||||||||||||||
| 299 | # since that is lowercase, it will become a von part. | ||||||||||||||||||||||||||||
| 300 | # | ||||||||||||||||||||||||||||
| 301 | # As a kludge, we simply avoid the loop if the first character is "&", | ||||||||||||||||||||||||||||
| 302 | # assuming it is an uppercase letter (TUGboat 46:1, | ||||||||||||||||||||||||||||
| 303 | # tb142konecny-opbible). If a von part truly does ever start with an | ||||||||||||||||||||||||||||
| 304 | # accented lowercase letter, this will fail. | ||||||||||||||||||||||||||||
| 305 | # | ||||||||||||||||||||||||||||
| 306 | 178 | ▶ | if ($string !~ /^&/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | 178 | ▶ | while ($string =~ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | s/^(\\[[:alpha:]]+\{|\{|\\[[:^alpha:]]?|[[:^alpha:]])//) { | ||||||||||||||||||||||||||||
| 309 | 8 | ▶ | if ($1 eq '{' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 5 | my $numbraces=1; | |||||||||||||||||||||||||||
| 311 | 5 | ▶ | while ($numbraces !=0 && length($string)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$numbraces != 0 and length $string
MC/DC50%1/2
$numbraces != 0 and length $string
$numbraces != 0
length $string
Truth table66%2/3
A and B
A= $numbraces != 0B= length $string
| |||||||||||||||||||||||||||||
| 312 | 66 | my $symbol = substr($string, 0, 1); | |||||||||||||||||||||||||||
| 313 | 66 | ▶ | if ($symbol eq '{') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 314 | 0 | $numbraces ++; | |||||||||||||||||||||||||||
| 315 | } elsif ($symbol eq '}') { | ||||||||||||||||||||||||||||
| 316 | 5 | $numbraces --; | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | 66 | $string = substr($string,1); | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 178 | ▶ | if (length $string ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | 173 | my $symbol = substr($string, 0, 1); | |||||||||||||||||||||||||||
| 326 | # We have to check against uc($symbol) not being the same, | ||||||||||||||||||||||||||||
| 327 | # rather than lc($symbol) being the same, because for a | ||||||||||||||||||||||||||||
| 328 | # non-alpha like "&", lc will indeed be the same. | ||||||||||||||||||||||||||||
| 329 | #warn " von symbol: $symbol, vs. ", uc($symbol), "\n"; | ||||||||||||||||||||||||||||
| 330 | 173 | ▶ | if (uc($symbol) ne $symbol) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 25 | return 1; | |||||||||||||||||||||||||||
| 332 | } else { | ||||||||||||||||||||||||||||
| 333 | 148 | return 0; | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | } else { | ||||||||||||||||||||||||||||
| 336 | 5 | return 1; | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 20 | 1; # End of BibTeX::Entry | |||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | __END__ | ||||||||||||||||||||||||||||