Skip to content

Commit

Permalink
#98 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed May 2, 2024
1 parent 699cad2 commit 361de78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 15 additions & 8 deletions bibcop.pl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ sub check_capitalization {
if (not exists $tags{$tag}) {
next;
}
my $tailed = qr/^.+(:|\?)$/;
my @ends = qw/ ; ? . --- : ! /;
my $value = $entry{$tag};
my @words = only_words($value);
my $pos = 0;
Expand All @@ -106,18 +106,20 @@ sub check_capitalization {
}
if (exists $minors{$word}) {
if ($pos eq 1) {
return "The minor word in the '$tag' must be upper-cased since it is the first one"
return "The minor word '$word' in the '$tag' must be upper-cased since it is the first one"
}
if (not $words[$pos - 2] =~ $tailed) {
next;
my $before = $words[$pos - 2];
if (grep(/^$before$/, @ends)) {
return "The minor word '$word' in the '$tag' must be upper-cased, because it follows the '$before'"
}
return "The minor word in the '$tag' must be upper-cased, because it follows the colon"
next;
}
if (exists $minors{lc($word)}) {
if ($pos eq 1) {
next;
}
if ($words[$pos - 2] =~ $tailed) {
my $before = $words[$pos - 2];
if (grep(/^$before$/, @ends)) {
next;
}
return "All minor words in the '$tag' must be lower-cased, while @{[as_position($pos)]} word '$word' is not"
Expand Down Expand Up @@ -178,7 +180,7 @@ sub check_shortenings {
next;
}
my $value = $entry{$tag};
my @words = only_words($value);
my @words = split(/ /, clean_tex($value));
foreach my $word (@words) {
if (not $word =~ /^[A-Za-z]/) {
next;
Expand Down Expand Up @@ -910,7 +912,12 @@ sub entries {
# Takes the text and returns only list of words seen there.
sub only_words {
my ($tex) = @_;
return split(/[ \-]/, clean_tex($tex));
my $t = clean_tex($tex);
$t =~ s/([^a-zA-Z0-9\\])/ $1 /g;
$t =~ s/- +- +-/---/g;
$t =~ s/{ /{/g;
$t =~ s/ }/}/g;
return split(/ +/, $t);
}

# Take a TeX string and return a cleaner one, without redundant spaces, brackets, etc.
Expand Down
1 change: 1 addition & 0 deletions perl-tests/checks.pl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ package bibcop;
check_passes($f, ('title' => 'Cilk: An Efficient Multithreaded Runtime System'));
check_passes($f, ('title' => 'Can Programming Be Liberated From the {von} Neumann Style? A Functional Style and Its Algebra of Programs'));
check_passes($f, ('title' => 'An Empirical Study of in C Code From GitHub'));
check_passes($f, ('title' => 'GitHub Audience?---A Thematic Analysis'));

$f = 'check_year';
check_fails($f, ('year' => 'hello'));
Expand Down

0 comments on commit 361de78

Please sign in to comment.