Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uppercase lone letters at end of titles #560

Merged
merged 3 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions expandFns.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ function title_capitalization($in, $caps_after_punctuation) {
$new_case = str_replace(UCFIRST_JOURNAL_ACRONYMS, JOURNAL_ACRONYMS, " " . $new_case . " ");
$new_case = substr($new_case, 1, strlen($new_case) - 2); // remove spaces, needed for matching in LC_SMALL_WORDS

// Single letter at end should be capitalized J Chem Phys E for example. Obviously not the spanish word "e".
$new_case = preg_replace_callback(
"~( [a-z])$~",
function ($matches) {return strtoupper($matches[1]);},
$new_case);

/* I believe we can do without this now
if (preg_match("~^(the|into|at?|of)\b~", $new_case)) {
// If first word is a little word, it should still be capitalized
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/expandFnsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function testCapitalization() {
title_capitalization(title_case('z/Journal'), TRUE));
$this->assertEquals('The Journal of Journals', // The, not the
title_capitalization('The Journal Of Journals', TRUE));
$this->assertEquals('A Journal of Chemistry A',
title_capitalization('A Journal of Chemistry A', TRUE));
$this->assertEquals('A Journal of Chemistry E',
title_capitalization('A Journal of Chemistry E', TRUE));
}

public function testFrenchCapitalization() {
Expand Down