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 1 commit
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +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)

Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
- We fixed an issue where title case didn't capitalize words after en-dash characters [#9068]
### 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,16 @@ 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("{BPMN} Conformance in Open Source Engines",
new TitleCaseFormatter().getExampleInput()));
}
Expand Down