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 warning display issue for entering a title made of two words #6054

Merged
merged 10 commits into from
Mar 17, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where the group and the link column were not updated after changing the entry in the main table. [#5985](https://github.com/JabRef/jabref/issues/5985)
- We fixed an issue where reordering the groups was not possible after inserting an article. [#6008](https://github.com/JabRef/jabref/issues/6008)
- We fixed an issue where citation styles except the default "Preview" could not be used. [#56220](https://github.com/JabRef/jabref/issues/5622)
- We fixed an issue where warning is displayed when title is made of two sentences. [#5832](https://github.com/JabRef/jabref/issues/5832)
eetian marked this conversation as resolved.
Show resolved Hide resolved

### Removed

Expand Down
28 changes: 17 additions & 11 deletions src/main/java/org/jabref/logic/integrity/TitleChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class TitleChecker implements ValueChecker {

private static final Pattern INSIDE_CURLY_BRAKETS = Pattern.compile("\\{[^}\\{]*\\}");
private static final String DELIMITERS = "(\\.|\\!|\\?|\\;|\\:)";
eetian marked this conversation as resolved.
Show resolved Hide resolved
private static final Predicate<String> HAS_CAPITAL_LETTERS = Pattern.compile("[\\p{Lu}\\p{Lt}]").asPredicate();

private final BibDatabaseContext databaseContext;
Expand All @@ -22,10 +23,12 @@ public TitleChecker(BibDatabaseContext databaseContext) {

/**
* Algorithm:
* - remove trailing whitespaces
* - ignore first letter as this can always be written in caps
* - remove everything that is in brackets
* - check if at least one capital letter is in the title
* - split the title into subTitles based on the delimiters
eetian marked this conversation as resolved.
Show resolved Hide resolved
* - for each subTitle:
eetian marked this conversation as resolved.
Show resolved Hide resolved
* - remove trailing whitespaces
* - ignore first letter as this can always be written in caps
* - check if at least one capital letter is in the title
eetian marked this conversation as resolved.
Show resolved Hide resolved
*/
@Override
public Optional<String> checkValue(String value) {
Expand All @@ -37,9 +40,7 @@ public Optional<String> checkValue(String value) {
return Optional.empty();
}

String valueTrimmed = value.trim();
String valueIgnoringFirstLetter = valueTrimmed.startsWith("{") ? valueTrimmed : valueTrimmed.substring(1);
String valueOnlySpacesWithinCurlyBraces = valueIgnoringFirstLetter;
String valueOnlySpacesWithinCurlyBraces = value;
while (true) {
Matcher matcher = INSIDE_CURLY_BRAKETS.matcher(valueOnlySpacesWithinCurlyBraces);
if (!matcher.find()) {
Expand All @@ -48,11 +49,16 @@ public Optional<String> checkValue(String value) {
valueOnlySpacesWithinCurlyBraces = matcher.replaceAll("");
}

boolean hasCapitalLettersThatBibtexWillConvertToSmallerOnes = HAS_CAPITAL_LETTERS
.test(valueOnlySpacesWithinCurlyBraces);

if (hasCapitalLettersThatBibtexWillConvertToSmallerOnes) {
return Optional.of(Localization.lang("capital letters are not masked using curly brackets {}"));
// Delimiters are . ! ? ; :
eetian marked this conversation as resolved.
Show resolved Hide resolved
String[] splitTitle = valueOnlySpacesWithinCurlyBraces.split(DELIMITERS);
for (String subTitle : splitTitle) {
subTitle = subTitle.trim();
if (subTitle.length() > 0) {
eetian marked this conversation as resolved.
Show resolved Hide resolved
subTitle = subTitle.substring(1);
}
if (HAS_CAPITAL_LETTERS.test(subTitle)) {
eetian marked this conversation as resolved.
Show resolved Hide resolved
return Optional.of(Localization.lang("capital letters are not masked using curly brackets {}"));
}
}

return Optional.empty();
Expand Down