Skip to content

Commit

Permalink
"Capitalize" capitalizes words after hyphens (#9186)
Browse files Browse the repository at this point in the history
* Fix for issue #9157. Added method that capitalizes first letter of every word, including words after hyphens.

* Added test cases for CapitalizeFormatter
  • Loading branch information
scarpio02 authored Sep 29, 2022
1 parent 246ce02 commit fca9fb9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue about selecting the save order in the preferences. [#9175](https://github.com/JabRef/jabref/issues/9147)
- We fixed an issue where the CSS styles are missing in some dialogs. [#9150](https://github.com/JabRef/jabref/pull/9150)
- We fixed an issue where pdfs were re-indexed on each startup. [#9166](https://github.com/JabRef/jabref/pull/9166)
- We fixed an issue where Capitalize didn't capitalize words after hyphen characters. [#9157](https://github.com/JabRef/jabref/issues/9157)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public String getKey() {
public String format(String input) {
Title title = new Title(input);

title.getWords().stream().forEach(Word::toUpperFirst);
title.getWords().stream().forEach(Word::toUpperFirstIgnoreHyphen);

return title.toString();
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/jabref/logic/formatter/casechanger/Word.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ public void toUpperFirst() {
}
}

public void toUpperFirstIgnoreHyphen() {
for (int i = 0; i < chars.length; i++) {
if (!protectedChars[i]) {
chars[i] = (i == 0 || (DASHES.contains(chars[i - 1]))) ?
Character.toUpperCase(chars[i]) :
Character.toLowerCase(chars[i]);
}
}
}

public void toUpperFirstTitle() {
for (int i = 0; i < chars.length; i++) {
if (!protectedChars[i]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public void formatExample() {
"UPPER {E}ACH {NOT} FIRST, Upper {E}ach {NOT} First", // multiple words upper case with {}
"upper each first {NOT} {this}, Upper Each First {NOT} {this}", // multiple words in lower and upper case with {}
"upper each first {N}OT {t}his, Upper Each First {N}ot {t}his", // multiple words in lower and upper case with {} part 2
"upper-each-first, Upper-Each-First", // multiple words lower case with -
"Upper-Each-First, Upper-Each-First", // multiple words correct with -
"Upper-each-First, Upper-Each-First", // multiple words in lower and upper case with -
"UPPER-EACH-FIRST, Upper-Each-First", // multiple words upper case with -
"{u}pper-each-{f}irst, {u}pper-Each-{f}irst", // multiple words lower case with {} and -
"-upper, -Upper", // single word with -
"-{u}pper, -{u}pper", // single word with {} and -
})
public void testInputs(String input, String expectedResult) {
String formattedStr = formatter.format(input);
Expand Down

0 comments on commit fca9fb9

Please sign in to comment.