Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fileDescr
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Siedlerchr committed Sep 13, 2017
2 parents 55e3d1d + 23a0610 commit d985361
Show file tree
Hide file tree
Showing 25 changed files with 756 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- 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)
- We fixed wrong hotkey being displayed at "automatically file links" in the entry editor
- 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)
- 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)
- Renaming files now truncates the filename to not exceed the limit of 255 chars [#2622](https://github.com/JabRef/jabref/issues/2622)
- We improved the handling of hyphens in names. [#2775](https://github.com/JabRef/jabref/issues/2775)

### Removed
- We removed support for LatexEditor, as it is not under active development. [#3199](https://github.com/JabRef/jabref/issues/3199)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ dependencies {
compile group: 'com.microsoft.azure', name: 'applicationinsights-logging-log4j2', version: '1.0.+'

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.9.0'
testCompile 'org.mockito:mockito-core:2.10.0'
testCompile 'com.github.tomakehurst:wiremock:2.8.0'
testCompile 'org.assertj:assertj-swing-junit:3.8.0'
testCompile 'org.reflections:reflections:0.9.11'
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.swing.AbstractAction;
import javax.swing.Action;
Expand Down Expand Up @@ -71,6 +73,7 @@
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.importer.EntryBasedFetcher;
import org.jabref.logic.importer.WebFetchers;
import org.jabref.logic.integrity.BracesCorrector;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.search.SearchQueryHighlightListener;
import org.jabref.logic.util.OS;
Expand All @@ -88,6 +91,7 @@
import org.apache.commons.logging.LogFactory;
import org.fxmisc.easybind.EasyBind;


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

private class CloseAction extends AbstractAction {

private CloseAction() {
super(Localization.lang("Close window"), IconTheme.JabRefIcon.CLOSE.getSmallIcon());
putValue(Action.SHORT_DESCRIPTION, Localization.lang("Close window"));
}

@Override
public void actionPerformed(ActionEvent e) {
Map<String,String> cleanedEntries = entry
.getFieldMap()
.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, f -> BracesCorrector.apply(f.getValue())));
if (!cleanedEntries.equals(entry.getFieldMap())) {
frame.output(Localization.lang("Added missing braces."));
}
entry.setField(cleanedEntries);
panel.entryEditorClosing(EntryEditor.this);
}
}
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/org/jabref/logic/integrity/BracesCorrector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.jabref.logic.integrity;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class BracesCorrector {

private static final Pattern PATTERN_ESCAPED_CURLY_BRACES = Pattern.compile("(\\\\\\{)|(\\\\\\})");
//private static final Pattern PATTERN_ESCAPED_CLOSING_CURLY_BRACE = Pattern.compile("");

public static String apply(String input) {
if (input == null) {
return null;
} else {
Matcher matcher = PATTERN_ESCAPED_CURLY_BRACES.matcher(input);
String addedBraces = input;
String c = matcher.replaceAll("");

long diff = c.chars().filter(ch -> ch == '{').count() - c.chars().filter(ch -> ch == '}').count();
while (diff != 0) {
if (diff < 0) {
addedBraces = "{" + addedBraces;
diff++;
} else {
addedBraces = addedBraces + "}";
diff--;
}
}
return addedBraces;
}
}

}
75 changes: 46 additions & 29 deletions src/main/java/org/jabref/model/entry/AuthorListParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,6 @@ public class AuthorListParser {
// Constant HashSet containing names of TeX special characters
private static final Set<String> TEX_NAMES = new HashSet<>();

/** the raw bibtex author/editor field */
private String original;

/** index of the start in original, for example to point to 'abc' in 'abc xyz', tokenStart=2 */
private int tokenStart;

/** index of the end in original, for example to point to 'abc' in 'abc xyz', tokenEnd=5 */
private int tokenEnd;

/** end of token abbreviation (always: tokenStart < tokenAbbr <= tokenEnd), only valid if getToken returns TOKEN_WORD */
private int tokenAbbr;


/** either space of dash */
private char tokenTerm;

/** true if upper-case token, false if lower-case */
private boolean tokenCase;

static {
TEX_NAMES.add("aa");
TEX_NAMES.add("ae");
Expand All @@ -66,6 +47,32 @@ public class AuthorListParser {
TEX_NAMES.add("j");
}

/**
* the raw bibtex author/editor field
*/
private String original;
/**
* index of the start in original, for example to point to 'abc' in 'abc xyz', tokenStart=2
*/
private int tokenStart;
/**
* index of the end in original, for example to point to 'abc' in 'abc xyz', tokenEnd=5
*/
private int tokenEnd;
/**
* end of token abbreviation (always: tokenStart < tokenAbbrEnd <= tokenEnd), only valid if getToken returns
* TOKEN_WORD
*/
private int tokenAbbrEnd;
/**
* either space of dash
*/
private char tokenTerm;
/**
* true if upper-case token, false if lower-case
*/
private boolean tokenCase;

/**
* Parses the String containing person names and returns a list of person information.
*
Expand Down Expand Up @@ -121,7 +128,7 @@ private Optional<Author> getAuthor() {
break;
case TOKEN_WORD:
tokens.add(original.substring(tokenStart, tokenEnd));
tokens.add(original.substring(tokenStart, tokenAbbr));
tokens.add(original.substring(tokenStart, tokenAbbrEnd));
tokens.add(tokenTerm);
tokens.add(tokenCase);
if (commaFirst >= 0) {
Expand All @@ -137,6 +144,13 @@ private Optional<Author> getAuthor() {
// We are in a first name which contained a hyphen
break;
}

int thisTermToken = previousTermToken + TOKEN_GROUP_LENGTH;
if ((thisTermToken >= 0) && tokens.get(thisTermToken).equals('-')) {
// We are in a name which contained a hyphen
break;
}

vonStart = tokens.size() - TOKEN_GROUP_LENGTH;
break;
}
Expand Down Expand Up @@ -194,14 +208,16 @@ private Optional<Author> getAuthor() {
firstPartStart = 0;
}
}
} else { // commas are present: it affects only 'first part' and
// 'junior part'
} else {
// commas are present: it affects only 'first part' and 'junior part'
firstPartEnd = tokens.size();
if (commaSecond < 0) { // one comma
if (commaSecond < 0) {
// one comma
if (commaFirst < firstPartEnd) {
firstPartStart = commaFirst;
}
} else { // two or more commas
} else {
// two or more commas
if (commaSecond < firstPartEnd) {
firstPartStart = commaSecond;
}
Expand Down Expand Up @@ -342,7 +358,7 @@ private int getToken() {
tokenEnd++;
return TOKEN_AND;
}
tokenAbbr = -1;
tokenAbbrEnd = -1;
tokenTerm = ' ';
tokenCase = true;
int bracesLevel = 0;
Expand All @@ -353,8 +369,9 @@ private int getToken() {
if (c == '{') {
bracesLevel++;
}
if (firstLetterIsFound && (tokenAbbr < 0) && ((bracesLevel == 0) || (c == '{'))) {
tokenAbbr = tokenEnd;

if (firstLetterIsFound && (tokenAbbrEnd < 0) && ((bracesLevel == 0) || (c == '{'))) {
tokenAbbrEnd = tokenEnd;
}
if ((c == '}') && (bracesLevel > 0)) {
bracesLevel--;
Expand Down Expand Up @@ -388,8 +405,8 @@ private int getToken() {
}
tokenEnd++;
}
if (tokenAbbr < 0) {
tokenAbbr = tokenEnd;
if (tokenAbbrEnd < 0) {
tokenAbbrEnd = tokenEnd;
}
if ((tokenEnd < original.length()) && (original.charAt(tokenEnd) == '-')) {
tokenTerm = '-';
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Add_to_group=Tilføj_i_gruppe

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

Added_missing_braces.=

Added_new=Tilføjede_ny

Added_string=Tilføjede_streng
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

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

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

Expand Down Expand Up @@ -69,6 +69,8 @@ Add_to_group=Zu_Gruppe_hinzufügen

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

Added_missing_braces.=Fehlende_Klammern_hinzugefügt.

Added_new=Neu_hinzugefügt

Added_string=String_hinzugefügt
Expand Down
Loading

0 comments on commit d985361

Please sign in to comment.