Skip to content

Commit

Permalink
Fix for issue JabRef#9157. Added method that capitalizes first letter…
Browse files Browse the repository at this point in the history
… of every word, including words after hyphens.
  • Loading branch information
scarpio02 committed Sep 27, 2022
1 parent 0ed4569 commit ef8581a
Show file tree
Hide file tree
Showing 3 changed files with 12 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

0 comments on commit ef8581a

Please sign in to comment.