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

Fix title case capitalization after en-dash characters #9102

Merged
merged 4 commits into from
Aug 31, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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. [#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)

Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
### 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