Skip to content

Commit d985361

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fileDescr
* upstream/master: Localization: French: Translation of a new string (#3212) Fix #2775: Hyphens in last names are properly parsed (#3209) Followup to Issue #3167 (#3202) Update mockito-core from 2.9.0 -> 2.10.0
2 parents 55e3d1d + 23a0610 commit d985361

25 files changed

+756
-38
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
3838
- We fixed an issue where the arrow keys in the search bar did not work as expected [#3081](https://github.com/JabRef/jabref/issues/3081)
3939
- We fixed wrong hotkey being displayed at "automatically file links" in the entry editor
4040
- We fixed an issue where metadata syncing with local and shared database were unstable. It will also fix syncing groups and sub-groups in database. [#2284](https://github.com/JabRef/jabref/issues/2284)
41+
- We fixed an issue where it was possible to leave the entry editor with an imbalance of braces. [#3167](https://github.com/JabRef/jabref/issues/3167)
4142
- Renaming files now truncates the filename to not exceed the limit of 255 chars [#2622](https://github.com/JabRef/jabref/issues/2622)
43+
- We improved the handling of hyphens in names. [#2775](https://github.com/JabRef/jabref/issues/2775)
4244

4345
### Removed
4446
- We removed support for LatexEditor, as it is not under active development. [#3199](https://github.com/JabRef/jabref/issues/3199)

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ dependencies {
128128
compile group: 'com.microsoft.azure', name: 'applicationinsights-logging-log4j2', version: '1.0.+'
129129

130130
testCompile 'junit:junit:4.12'
131-
testCompile 'org.mockito:mockito-core:2.9.0'
131+
testCompile 'org.mockito:mockito-core:2.10.0'
132132
testCompile 'com.github.tomakehurst:wiremock:2.8.0'
133133
testCompile 'org.assertj:assertj-swing-junit:3.8.0'
134134
testCompile 'org.reflections:reflections:0.9.11'

src/main/java/org/jabref/gui/entryeditor/EntryEditor.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
import java.awt.event.MouseEvent;
1414
import java.util.ArrayList;
1515
import java.util.List;
16+
import java.util.Map;
1617
import java.util.Objects;
1718
import java.util.Optional;
19+
import java.util.stream.Collectors;
1820

1921
import javax.swing.AbstractAction;
2022
import javax.swing.Action;
@@ -71,6 +73,7 @@
7173
import org.jabref.logic.help.HelpFile;
7274
import org.jabref.logic.importer.EntryBasedFetcher;
7375
import org.jabref.logic.importer.WebFetchers;
76+
import org.jabref.logic.integrity.BracesCorrector;
7477
import org.jabref.logic.l10n.Localization;
7578
import org.jabref.logic.search.SearchQueryHighlightListener;
7679
import org.jabref.logic.util.OS;
@@ -88,6 +91,7 @@
8891
import org.apache.commons.logging.LogFactory;
8992
import org.fxmisc.easybind.EasyBind;
9093

94+
9195
/**
9296
* GUI component that allows editing of the fields of a BibEntry (i.e. the
9397
* one that shows up, when you double click on an entry in the table)
@@ -631,14 +635,22 @@ public void actionPerformed(ActionEvent e) {
631635
}
632636

633637
private class CloseAction extends AbstractAction {
634-
635638
private CloseAction() {
636639
super(Localization.lang("Close window"), IconTheme.JabRefIcon.CLOSE.getSmallIcon());
637640
putValue(Action.SHORT_DESCRIPTION, Localization.lang("Close window"));
638641
}
639642

640643
@Override
641644
public void actionPerformed(ActionEvent e) {
645+
Map<String,String> cleanedEntries = entry
646+
.getFieldMap()
647+
.entrySet()
648+
.stream()
649+
.collect(Collectors.toMap(Map.Entry::getKey, f -> BracesCorrector.apply(f.getValue())));
650+
if (!cleanedEntries.equals(entry.getFieldMap())) {
651+
frame.output(Localization.lang("Added missing braces."));
652+
}
653+
entry.setField(cleanedEntries);
642654
panel.entryEditorClosing(EntryEditor.this);
643655
}
644656
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.jabref.logic.integrity;
2+
3+
import java.util.regex.Matcher;
4+
import java.util.regex.Pattern;
5+
6+
public class BracesCorrector {
7+
8+
private static final Pattern PATTERN_ESCAPED_CURLY_BRACES = Pattern.compile("(\\\\\\{)|(\\\\\\})");
9+
//private static final Pattern PATTERN_ESCAPED_CLOSING_CURLY_BRACE = Pattern.compile("");
10+
11+
public static String apply(String input) {
12+
if (input == null) {
13+
return null;
14+
} else {
15+
Matcher matcher = PATTERN_ESCAPED_CURLY_BRACES.matcher(input);
16+
String addedBraces = input;
17+
String c = matcher.replaceAll("");
18+
19+
long diff = c.chars().filter(ch -> ch == '{').count() - c.chars().filter(ch -> ch == '}').count();
20+
while (diff != 0) {
21+
if (diff < 0) {
22+
addedBraces = "{" + addedBraces;
23+
diff++;
24+
} else {
25+
addedBraces = addedBraces + "}";
26+
diff--;
27+
}
28+
}
29+
return addedBraces;
30+
}
31+
}
32+
33+
}

src/main/java/org/jabref/model/entry/AuthorListParser.java

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,6 @@ public class AuthorListParser {
3232
// Constant HashSet containing names of TeX special characters
3333
private static final Set<String> TEX_NAMES = new HashSet<>();
3434

35-
/** the raw bibtex author/editor field */
36-
private String original;
37-
38-
/** index of the start in original, for example to point to 'abc' in 'abc xyz', tokenStart=2 */
39-
private int tokenStart;
40-
41-
/** index of the end in original, for example to point to 'abc' in 'abc xyz', tokenEnd=5 */
42-
private int tokenEnd;
43-
44-
/** end of token abbreviation (always: tokenStart < tokenAbbr <= tokenEnd), only valid if getToken returns TOKEN_WORD */
45-
private int tokenAbbr;
46-
47-
48-
/** either space of dash */
49-
private char tokenTerm;
50-
51-
/** true if upper-case token, false if lower-case */
52-
private boolean tokenCase;
53-
5435
static {
5536
TEX_NAMES.add("aa");
5637
TEX_NAMES.add("ae");
@@ -66,6 +47,32 @@ public class AuthorListParser {
6647
TEX_NAMES.add("j");
6748
}
6849

50+
/**
51+
* the raw bibtex author/editor field
52+
*/
53+
private String original;
54+
/**
55+
* index of the start in original, for example to point to 'abc' in 'abc xyz', tokenStart=2
56+
*/
57+
private int tokenStart;
58+
/**
59+
* index of the end in original, for example to point to 'abc' in 'abc xyz', tokenEnd=5
60+
*/
61+
private int tokenEnd;
62+
/**
63+
* end of token abbreviation (always: tokenStart < tokenAbbrEnd <= tokenEnd), only valid if getToken returns
64+
* TOKEN_WORD
65+
*/
66+
private int tokenAbbrEnd;
67+
/**
68+
* either space of dash
69+
*/
70+
private char tokenTerm;
71+
/**
72+
* true if upper-case token, false if lower-case
73+
*/
74+
private boolean tokenCase;
75+
6976
/**
7077
* Parses the String containing person names and returns a list of person information.
7178
*
@@ -121,7 +128,7 @@ private Optional<Author> getAuthor() {
121128
break;
122129
case TOKEN_WORD:
123130
tokens.add(original.substring(tokenStart, tokenEnd));
124-
tokens.add(original.substring(tokenStart, tokenAbbr));
131+
tokens.add(original.substring(tokenStart, tokenAbbrEnd));
125132
tokens.add(tokenTerm);
126133
tokens.add(tokenCase);
127134
if (commaFirst >= 0) {
@@ -137,6 +144,13 @@ private Optional<Author> getAuthor() {
137144
// We are in a first name which contained a hyphen
138145
break;
139146
}
147+
148+
int thisTermToken = previousTermToken + TOKEN_GROUP_LENGTH;
149+
if ((thisTermToken >= 0) && tokens.get(thisTermToken).equals('-')) {
150+
// We are in a name which contained a hyphen
151+
break;
152+
}
153+
140154
vonStart = tokens.size() - TOKEN_GROUP_LENGTH;
141155
break;
142156
}
@@ -194,14 +208,16 @@ private Optional<Author> getAuthor() {
194208
firstPartStart = 0;
195209
}
196210
}
197-
} else { // commas are present: it affects only 'first part' and
198-
// 'junior part'
211+
} else {
212+
// commas are present: it affects only 'first part' and 'junior part'
199213
firstPartEnd = tokens.size();
200-
if (commaSecond < 0) { // one comma
214+
if (commaSecond < 0) {
215+
// one comma
201216
if (commaFirst < firstPartEnd) {
202217
firstPartStart = commaFirst;
203218
}
204-
} else { // two or more commas
219+
} else {
220+
// two or more commas
205221
if (commaSecond < firstPartEnd) {
206222
firstPartStart = commaSecond;
207223
}
@@ -342,7 +358,7 @@ private int getToken() {
342358
tokenEnd++;
343359
return TOKEN_AND;
344360
}
345-
tokenAbbr = -1;
361+
tokenAbbrEnd = -1;
346362
tokenTerm = ' ';
347363
tokenCase = true;
348364
int bracesLevel = 0;
@@ -353,8 +369,9 @@ private int getToken() {
353369
if (c == '{') {
354370
bracesLevel++;
355371
}
356-
if (firstLetterIsFound && (tokenAbbr < 0) && ((bracesLevel == 0) || (c == '{'))) {
357-
tokenAbbr = tokenEnd;
372+
373+
if (firstLetterIsFound && (tokenAbbrEnd < 0) && ((bracesLevel == 0) || (c == '{'))) {
374+
tokenAbbrEnd = tokenEnd;
358375
}
359376
if ((c == '}') && (bracesLevel > 0)) {
360377
bracesLevel--;
@@ -388,8 +405,8 @@ private int getToken() {
388405
}
389406
tokenEnd++;
390407
}
391-
if (tokenAbbr < 0) {
392-
tokenAbbr = tokenEnd;
408+
if (tokenAbbrEnd < 0) {
409+
tokenAbbrEnd = tokenEnd;
393410
}
394411
if ((tokenEnd < original.length()) && (original.charAt(tokenEnd) == '-')) {
395412
tokenTerm = '-';

src/main/resources/l10n/JabRef_da.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Add_to_group=Tilføj_i_gruppe
6969

7070
Added_group_"%0".=Tilføjede_gruppe_"%0".
7171

72+
Added_missing_braces.=
73+
7274
Added_new=Tilføjede_ny
7375

7476
Added_string=Tilføjede_streng

src/main/resources/l10n/JabRef_de.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#!
3-
#!created/edited_by_Popeye_version_0.55_(github.com/JabRef/popeye)
4-
#!encoding:UTF-8
3+
#! created/edited by Popeye version 0.55 (github.com/JabRef/popeye)
4+
#! encoding:UTF-8
55

66
%0_contains_the_regular_expression_<b>%1</b>=%0_den_regulären_Ausdruck_<b>%1</b>_enthält
77

@@ -69,6 +69,8 @@ Add_to_group=Zu_Gruppe_hinzufügen
6969

7070
Added_group_"%0".=Gruppe_"%0"_hinzugefügt.
7171

72+
Added_missing_braces.=Fehlende_Klammern_hinzugefügt.
73+
7274
Added_new=Neu_hinzugefügt
7375

7476
Added_string=String_hinzugefügt

0 commit comments

Comments
 (0)