Skip to content

Commit

Permalink
Fix title case capitalization after en-dash characters (#9102)
Browse files Browse the repository at this point in the history
* Fix for issue 9068 - Title case en-dash capitalization

* add original issue as test case
fix isi importer

* fix checkstyle

Co-authored-by: Christoph <siedlerkiller@gmail.com>
  • Loading branch information
MorettiGS and Siedlerchr authored Aug 31, 2022
1 parent 3a97f54 commit 88d9d83
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed a bug where spaces are trimmed when highlighting differences in the Entries merge dialog. [koppor#371](https://github.com/koppor/jabref/issues/371)
- We fixed several bugs regarding the manual and the autosave of library files that sometimes lead to exceptions or data loss. [#9067](https://github.com/JabRef/jabref/pull/9067), [#8448](https://github.com/JabRef/jabref/issues/8484), [#8746](https://github.com/JabRef/jabref/issues/8746), [#6684](https://github.com/JabRef/jabref/issues/6684), [#6644](https://github.com/JabRef/jabref/issues/6644), [#6102](https://github.com/JabRef/jabref/issues/6102), [#6002](https://github.com/JabRef/jabref/issues/6000)
- We fixed an issue where applied save actions on saving the library file would lead to the dialog "The libary has been modified by another program" popping up [#4877](https://github.com/JabRef/jabref/issues/4877)
- We fixed an issue where title case didn't capitalize words after en-dash characters [#9068]
- We fixed an issue where JabRef would not exit when a connection to a LibreOffice document was established previously and the document is still open [#9075](https://github.com/JabRef/jabref/issues/9075)

### Removed
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/org/jabref/logic/formatter/casechanger/Word.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public final class Word {
* Set containing common lowercase function words
*/
public static final Set<String> SMALLER_WORDS;
public static final Set<Character> DASHES;
private final char[] chars;
private final boolean[] protectedChars;

static {
Set<String> smallerWords = new HashSet<>();
Set<Character> dashes = new HashSet<>();

// Articles
smallerWords.addAll(Arrays.asList("a", "an", "the"));
Expand All @@ -30,10 +32,20 @@ public final class Word {
// Conjunctions
smallerWords.addAll(Arrays.asList("and", "but", "for", "nor", "or", "so", "yet"));

// Dashes
dashes.addAll(Arrays.asList(
'-', '~', '⸗', '〰', '᐀', '֊', '־', '‐', '‑', '‒',
'–', '—', '―', '⁓', '⁻', '₋', '−', '⸺', '⸻',
'〜', '゠', '︱', '︲', '﹘', '﹣', '-'
));

// unmodifiable for thread safety
DASHES = dashes;

// unmodifiable for thread safety
SMALLER_WORDS = smallerWords.stream()
.map(word -> word.toLowerCase(Locale.ROOT))
.collect(Collectors.toUnmodifiableSet());
.map(word -> word.toLowerCase(Locale.ROOT))
.collect(Collectors.toUnmodifiableSet());
}

public Word(char[] chars, boolean[] protectedChars) {
Expand Down Expand Up @@ -77,7 +89,7 @@ public void toLowerCase() {
public void toUpperFirst() {
for (int i = 0; i < chars.length; i++) {
if (!protectedChars[i]) {
chars[i] = (i == 0) ?
chars[i] = (i == 0 || DASHES.contains(chars[i - 1])) ?
Character.toUpperCase(chars[i]) :
Character.toLowerCase(chars[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ private static Stream<Arguments> testData() {
"bibliographic software. a comparison."),
Arguments.of("Bibliographic Software. {A COMPARISON.}",
"bibliographic software. {A COMPARISON.}"),
Arguments.of("--Test~Ing Dash--Like Characters",
"--test~ing dash--like characters"),
Arguments.of("-⸗Test⸗Ing Dash〰Like Cha᐀᐀Racters",
"-⸗test⸗ing dash〰like cha᐀᐀racters"),
Arguments.of("︲︲Test־Ing Dash⁓⁓Like Characters",
"︲︲test־ing dash⁓⁓like characters"),
Arguments.of("⁻⁻Test−Ing Dash⸻Like Characters",
"⁻⁻test−ing dash⸻like characters"),
Arguments.of("--Test〰Ing M-U~L゠T︱I⁓P︲L--~~︲E Dash⸻-Like Characters",
"--test〰ing M-u~l゠t︱i⁓p︲l--~~︲e dASH⸻-likE charACTErs"),
Arguments.of("Kinetic Studies on Enzyme-Catalyzed Reactions: Oxidation of Glucose, Decomposition of Hydrogen Peroxide and Their Combination",
"kinetic studies on enzyme-catalyzed reactions: oxidation of glucose, decomposition of hydrogen peroxide and their combination"),
Arguments.of("{BPMN} Conformance in Open Source Engines",
new TitleCaseFormatter().getExampleInput()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void testImportEntriesWOS() throws IOException, URISyntaxException {
assertEquals(Optional.of("Optical waveguides in Sn2P2S6 by low fluence MeV He+ ion implantation"),
second.getField(StandardField.TITLE));

assertEquals(Optional.of("Journal of Physics-condensed Matter"), first.getField(StandardField.JOURNAL));
assertEquals(Optional.of("Journal of Physics-Condensed Matter"), first.getField(StandardField.JOURNAL));
}

@Test
Expand Down

0 comments on commit 88d9d83

Please sign in to comment.