From 8dcf61458c514fee577b6f3d40e4d17256afc282 Mon Sep 17 00:00:00 2001 From: Rolf Starre Date: Fri, 17 Mar 2017 13:07:41 +0100 Subject: [PATCH 1/9] Added test cases for key pattern modifiers to auth and shorttitle patterns --- .../casechanger/SentenceCaseFormatter.java | 2 +- .../MakeLabelWithDatabaseTest.java | 70 ++++++++++++++++++- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatter.java b/src/main/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatter.java index 91082d76e9e..87342d63b3d 100644 --- a/src/main/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatter.java @@ -16,7 +16,7 @@ public String getKey() { } /** - * Converts the first character of the first word of the given string to upper case (and the remaining characters of the first word to lower case), but does not change anything if word starts with "{" + * Converts the first character of the first word of the given string to upper case (and the remaining characters of the first word to lower case) and changes other words to lower case, but does not change anything if word starts with "{" */ @Override public String format(String input) { diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java index 809b4d16ee8..cd345e04ecd 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java @@ -123,19 +123,40 @@ public void generateDefaultKeyFirstTwoAlreadyExists() { } @Test - public void generateDefaultKeyLowerModified() { + public void generateKeyAuthLowerModified() { bibtexKeyPattern.setDefaultValue("[auth:lower][year]"); BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); assertEquals(Optional.of("doe2016"), entry.getCiteKeyOptional()); } @Test - public void generateDefaultKeyUpperModified() { + public void generateKeyAuthUpperModified() { bibtexKeyPattern.setDefaultValue("[auth:upper][year]"); BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); assertEquals(Optional.of("DOE2016"), entry.getCiteKeyOptional()); } + @Test + public void generateKeyAuthTitleCaseModified() { + bibtexKeyPattern.setDefaultValue("[auth:title_case][year]"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("Doe2016"), entry.getCiteKeyOptional()); + } + + @Test + public void generateKeyAuthSentenceCaseModified() { + bibtexKeyPattern.setDefaultValue("[auth:sentence_case][year]"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("Doe2016"), entry.getCiteKeyOptional()); + } + + @Test + public void generateKeyAuthCapitalizeModified() { + bibtexKeyPattern.setDefaultValue("[auth:capitalize][year]"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("Doe2016"), entry.getCiteKeyOptional()); + } + @Test public void generateDefaultKeyFixedValue() { bibtexKeyPattern.setDefaultValue("[auth]Test[year]"); @@ -208,6 +229,51 @@ public void generateKeyShorttitle() { assertEquals(Optional.of("Anawesomepaper"), entry.getCiteKeyOptional()); } + @Test + public void generateKeyShorttitleLowerModified() { + bibtexKeyPattern.setDefaultValue("[shorttitle:lower]"); + BibEntry entry2 = new BibEntry(); + entry2.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); + assertEquals(Optional.of("anawesomepaper"), entry2.getCiteKeyOptional()); + } + + @Test + public void generateKeyShorttitleUpperModified() { + bibtexKeyPattern.setDefaultValue("[shorttitle:upper]"); + BibEntry entry2 = new BibEntry(); + entry2.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); + assertEquals(Optional.of("ANAWESOMEPAPER"), entry2.getCiteKeyOptional()); + } + + @Test + public void generateKeyShorttitleTitleCaseModified() { + bibtexKeyPattern.setDefaultValue("[shorttitle:title_case]"); + BibEntry entry2 = new BibEntry(); + entry2.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); + assertEquals(Optional.of("AnAwesomePaper"), entry2.getCiteKeyOptional()); + } + + @Test + public void generateKeyShorttitleSentenceCaseModified() { + bibtexKeyPattern.setDefaultValue("[shorttitle:sentence_case]"); + BibEntry entry2 = new BibEntry(); + entry2.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); + assertEquals(Optional.of("Anawesomepaper"), entry2.getCiteKeyOptional()); + } + + @Test + public void generateKeyShorttitleCapitalizeModified() { + bibtexKeyPattern.setDefaultValue("[shorttitle:capitalize]"); + BibEntry entry2 = new BibEntry(); + entry2.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); + assertEquals(Optional.of("AnAwesomePaper"), entry2.getCiteKeyOptional()); + } + @Test public void generateKeyVeryshorttitle() { bibtexKeyPattern.setDefaultValue("[veryshorttitle]"); From 43cd266f8b4749b85c3adda4e19ed846e8650090 Mon Sep 17 00:00:00 2001 From: Rolf Starre Date: Fri, 17 Mar 2017 22:31:33 +0100 Subject: [PATCH 2/9] Added tests for veryshortttitle with modifiers and quick fix for shortitle with capitalize and title case --- .../BibtexKeyPatternUtil.java | 2 +- .../BibtexKeyPatternUtilTest.java | 18 ++--- .../MakeLabelWithDatabaseTest.java | 75 ++++++++++++++----- 3 files changed, 65 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java b/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java index 7f2c56e6653..e22be0ca125 100644 --- a/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java +++ b/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java @@ -726,7 +726,7 @@ private static String getAddition(int number) { * Determines "number" words out of the "title" field in the given BibTeX entry */ public static String getTitleWords(int number, String title) { - return keepLettersAndDigitsOnly(getTitleWordsWithSpaces(number, title)); + return getTitleWordsWithSpaces(number, title); } /** diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtilTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtilTest.java index 8b7da969d6a..42fd5c8d61c 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtilTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtilTest.java @@ -651,20 +651,20 @@ public void veryShortTitle() { public void shortTitle() { // shortTitle is getTitleWords with "3" as count int count = 3; - assertEquals("applicationmigrationeffort", + assertEquals("application migration effort", BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH)); - assertEquals("BPELconformancein", BibtexKeyPatternUtil.getTitleWords(count, + assertEquals("BPEL conformance in", BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); - assertEquals("ProcessViewingPatterns", BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED)); - assertEquals("BPMNConformancein", + assertEquals("Process Viewing Patterns", BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED)); + assertEquals("BPMN Conformance in", BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD)); - assertEquals("TheDifferenceBetween", BibtexKeyPatternUtil.getTitleWords(count, + assertEquals("The Difference Between", BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING)); - assertEquals("CloudComputingThe", + assertEquals("Cloud Computing: The", BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); - assertEquals("TowardsChoreographybased", + assertEquals("Towards Choreography based", BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD)); - assertEquals("OntheMeasurement", + assertEquals("On the Measurement", BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS)); } @@ -785,7 +785,7 @@ public void testApplyModifiers() { BibEntry entry = new BibEntry(); entry.setField("title", "Green Scheduling of Whatever"); assertEquals("GSo", BibtexKeyPatternUtil.makeLabel(entry, "shorttitleINI", ',', new BibDatabase())); - assertEquals("GreenSchedulingof", BibtexKeyPatternUtil.makeLabel(entry, "shorttitle", + assertEquals("Green Scheduling of", BibtexKeyPatternUtil.makeLabel(entry, "shorttitle", ',', new BibDatabase())); } diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java index cd345e04ecd..06143a00253 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java @@ -232,46 +232,41 @@ public void generateKeyShorttitle() { @Test public void generateKeyShorttitleLowerModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:lower]"); - BibEntry entry2 = new BibEntry(); - entry2.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); - assertEquals(Optional.of("anawesomepaper"), entry2.getCiteKeyOptional()); + entry.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("anawesomepaper"), entry.getCiteKeyOptional()); } @Test public void generateKeyShorttitleUpperModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:upper]"); - BibEntry entry2 = new BibEntry(); - entry2.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); - assertEquals(Optional.of("ANAWESOMEPAPER"), entry2.getCiteKeyOptional()); + entry.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("ANAWESOMEPAPER"), entry.getCiteKeyOptional()); } @Test public void generateKeyShorttitleTitleCaseModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:title_case]"); - BibEntry entry2 = new BibEntry(); - entry2.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); - assertEquals(Optional.of("AnAwesomePaper"), entry2.getCiteKeyOptional()); + entry.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("AnAwesomePaper"), entry.getCiteKeyOptional()); } @Test public void generateKeyShorttitleSentenceCaseModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:sentence_case]"); - BibEntry entry2 = new BibEntry(); - entry2.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); - assertEquals(Optional.of("Anawesomepaper"), entry2.getCiteKeyOptional()); + entry.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("Anawesomepaper"), entry.getCiteKeyOptional()); } @Test public void generateKeyShorttitleCapitalizeModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:capitalize]"); - BibEntry entry2 = new BibEntry(); - entry2.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); - assertEquals(Optional.of("AnAwesomePaper"), entry2.getCiteKeyOptional()); + entry.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("AnAwesomePaper"), entry.getCiteKeyOptional()); } @Test @@ -281,6 +276,46 @@ public void generateKeyVeryshorttitle() { assertEquals(Optional.of("awesome"), entry.getCiteKeyOptional()); } + @Test + public void generateKeyVeryshorttitleLowerModified() { + bibtexKeyPattern.setDefaultValue("[veryshorttitle:lower]"); + entry.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("awesome"), entry.getCiteKeyOptional()); + } + + @Test + public void generateKeyVeryshorttitleUpperModified() { + bibtexKeyPattern.setDefaultValue("[veryshorttitle:upper]"); + entry.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("AWESOME"), entry.getCiteKeyOptional()); + } + + @Test + public void generateKeyVeryshorttitleTitleCaseModified() { + bibtexKeyPattern.setDefaultValue("[veryshorttitle:title_case]"); + entry.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("Awesome"), entry.getCiteKeyOptional()); + } + + @Test + public void generateKeyVeryshorttitleSentenceCaseModified() { + bibtexKeyPattern.setDefaultValue("[veryshorttitle:sentence_case]"); + entry.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("Awesome"), entry.getCiteKeyOptional()); + } + + @Test + public void generateKeyVeryshorttitleCapitalizeModified() { + bibtexKeyPattern.setDefaultValue("[veryshorttitle:capitalize]"); + entry.setField("title", "An aweSOme Paper on JabRef"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("Awesome"), entry.getCiteKeyOptional()); + } + @Test public void generateKeyShorttitleINI() { bibtexKeyPattern.setDefaultValue("[shorttitleINI]"); From 04cde602b4abc87c80fa349f3f78e7a06cde79e0 Mon Sep 17 00:00:00 2001 From: Rolf Starre Date: Sat, 18 Mar 2017 01:39:30 +0100 Subject: [PATCH 3/9] Initial attempt at creating a regex modifier for key patterns --- .../jabref/logic/formatter/Formatters.java | 13 ++++- .../bibtexfields/RegexFormatter.java | 49 +++++++++++++++++++ .../MakeLabelWithDatabaseTest.java | 8 +++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java diff --git a/src/main/java/org/jabref/logic/formatter/Formatters.java b/src/main/java/org/jabref/logic/formatter/Formatters.java index 862f97d65a9..27540ce0089 100644 --- a/src/main/java/org/jabref/logic/formatter/Formatters.java +++ b/src/main/java/org/jabref/logic/formatter/Formatters.java @@ -16,6 +16,7 @@ import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; import org.jabref.logic.formatter.bibtexfields.OrdinalsToSuperscriptFormatter; +import org.jabref.logic.formatter.bibtexfields.RegexFormatter; import org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter; import org.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter; import org.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter; @@ -56,6 +57,7 @@ public class Formatters { new NormalizeNamesFormatter(), new NormalizePagesFormatter(), new OrdinalsToSuperscriptFormatter(), + new RegexFormatter(), new RemoveBracesFormatter(), new UnitsToLatexFormatter(), new EscapeUnderscoresFormatter() @@ -68,7 +70,16 @@ private Formatters() { public static Optional getFormatterForModifier(String modifier) { Objects.requireNonNull(modifier); - Optional formatter = ALL.stream().filter(f -> f.getKey().equals(modifier)).findAny(); + Optional formatter; + + if (modifier.matches("regex.*")) { + String regex = modifier.substring(5); + RegexFormatter.setRegex(regex); + formatter = ALL.stream().filter(f -> f.getKey().equals("regex")).findAny(); + + } else { + formatter = ALL.stream().filter(f -> f.getKey().equals(modifier)).findAny(); + } if (formatter.isPresent()) { return formatter; } diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java new file mode 100644 index 00000000000..cd3d261aece --- /dev/null +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java @@ -0,0 +1,49 @@ +package org.jabref.logic.formatter.bibtexfields; + +import java.util.Objects; + +import org.jabref.logic.l10n.Localization; +import org.jabref.model.cleanup.Formatter; + +public class RegexFormatter implements Formatter { + + private static String[] rex; + + @Override + public String getName() { + return Localization.lang("Regex"); + } + + @Override + public String getKey() { + return "regex"; + } + + @Override + public String format(String oldString) { + Objects.requireNonNull(oldString); + rex[0] = rex[0].replaceAll("\"", ""); + rex[1] = rex[1].replaceAll("\"", ""); + + return oldString.replaceAll(rex[0], rex[1]); + } + + @Override + public String getDescription() { + return Localization.lang("Add a regular expression for the key pattern."); + } + + @Override + public String getExampleInput() { + return "Please replace the spaces"; + } + + public static void setRegex(String regex) { + regex = regex.substring(1, regex.length() - 1); + String[] parts = regex.split("\",\""); + parts[0] += "\""; + parts[1] = "\"" + parts[1]; + rex = parts; + } + +} diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java index 06143a00253..8098382567f 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java @@ -387,6 +387,14 @@ public void generateKeyAuthIniMany() { assertEquals(Optional.of("DoeSmiWon"), entry.getCiteKeyOptional()); } + @Test + public void generateKeyTitleRegexe() { + bibtexKeyPattern.setDefaultValue("[title:regex(\" \",\"-\")]"); + entry.setField("title", "Please replace the spaces"); + BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + assertEquals(Optional.of("Please-Replace-the-Spaces"), entry.getCiteKeyOptional()); + } + @Test public void generateKeyTitleTitleCase() { bibtexKeyPattern.setDefaultValue("[title:title_case]"); From 9aa9d6e17a35262ad975bf9d30f451eeb396b22c Mon Sep 17 00:00:00 2001 From: Rolf Starre Date: Mon, 20 Mar 2017 16:21:16 +0100 Subject: [PATCH 4/9] Added tests for regexformatter --- .../bibtexfields/RegexFormatter.java | 26 +++++++-------- src/main/resources/l10n/JabRef_da.properties | 2 ++ src/main/resources/l10n/JabRef_de.properties | 2 ++ src/main/resources/l10n/JabRef_en.properties | 4 +++ src/main/resources/l10n/JabRef_es.properties | 2 ++ src/main/resources/l10n/JabRef_fa.properties | 2 ++ src/main/resources/l10n/JabRef_fr.properties | 2 ++ src/main/resources/l10n/JabRef_in.properties | 2 ++ src/main/resources/l10n/JabRef_it.properties | 2 ++ src/main/resources/l10n/JabRef_ja.properties | 2 ++ src/main/resources/l10n/JabRef_nl.properties | 2 ++ src/main/resources/l10n/JabRef_no.properties | 2 ++ .../resources/l10n/JabRef_pt_BR.properties | 2 ++ src/main/resources/l10n/JabRef_ru.properties | 2 ++ src/main/resources/l10n/JabRef_sv.properties | 2 ++ src/main/resources/l10n/JabRef_tr.properties | 2 ++ src/main/resources/l10n/JabRef_vi.properties | 2 ++ src/main/resources/l10n/JabRef_zh.properties | 2 ++ .../jabref/logic/formatter/FormatterTest.java | 2 ++ .../bibtexfields/RegexFormatterTest.java | 32 +++++++++++++++++++ 20 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 src/test/java/org/jabref/logic/formatter/bibtexfields/RegexFormatterTest.java diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java index cd3d261aece..ba01035a435 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java @@ -1,13 +1,11 @@ package org.jabref.logic.formatter.bibtexfields; -import java.util.Objects; - import org.jabref.logic.l10n.Localization; import org.jabref.model.cleanup.Formatter; public class RegexFormatter implements Formatter { - private static String[] rex; + private static String[] regex; @Override public String getName() { @@ -20,12 +18,11 @@ public String getKey() { } @Override - public String format(String oldString) { - Objects.requireNonNull(oldString); - rex[0] = rex[0].replaceAll("\"", ""); - rex[1] = rex[1].replaceAll("\"", ""); - - return oldString.replaceAll(rex[0], rex[1]); + public String format(String input) { + if (regex == null) { + return input; + } + return input.replaceAll(regex[0], regex[1]); } @Override @@ -38,12 +35,11 @@ public String getExampleInput() { return "Please replace the spaces"; } - public static void setRegex(String regex) { - regex = regex.substring(1, regex.length() - 1); - String[] parts = regex.split("\",\""); - parts[0] += "\""; - parts[1] = "\"" + parts[1]; - rex = parts; + public static void setRegex(String rex) { + // formatting is like ("exp1","exp2"), we want to remove (" and ") + rex = rex.substring(2, rex.length() - 2); + String[] parts = rex.split("\",\""); + regex = parts; } } diff --git a/src/main/resources/l10n/JabRef_da.properties b/src/main/resources/l10n/JabRef_da.properties index 2633a21f402..77cb004cfc0 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -991,6 +991,8 @@ Reference_library=Referencelibrary Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Undergruppe\:_Vis_poster_indeholdt_både_i_denne_gruppe_og_gruppe_over +Regex= + regular_expression=Regulærudtryk Related_articles= diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index e35a51b8d67..faa1d83238c 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -991,6 +991,8 @@ Reference_library=Referenz-Datenbank Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Obergruppe_einbeziehen\:_Einträge_aus_dieser_Gruppe_und_ihrer_übergeordneten_Gruppe_anzeigen +Regex= + regular_expression=Regulärer_Ausdruck Related_articles=ähnliche_Dokumente diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 960f46d3eca..447e40e2394 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -50,6 +50,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=The_path_need_not_be_on_the_cla Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef. +Add_a_regular_expression_for_the_key_pattern.=Add_a_regular_expression_for_the_key_pattern. + Add_entry_selection_to_this_group=Add_entry_selection_to_this_group Add_from_folder=Add_from_folder @@ -991,6 +993,8 @@ Reference_library=Reference_library Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup +Regex=Regex + regular_expression=regular_expression Related_articles=Related_articles diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index 41a9e6d91c0..3729f9f79e7 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -991,6 +991,8 @@ Reference_library=Base_de_datos_de_referencia Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Refinar_supergrupo\:_Ver_entradas_contenidas_en_este_grupo_y_sus_subgrupos_cuando_estén_seleccionadas +Regex= + regular_expression=Expresión_Regular Related_articles= diff --git a/src/main/resources/l10n/JabRef_fa.properties b/src/main/resources/l10n/JabRef_fa.properties index bb43554a84e..481fe4ba0dd 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -991,6 +991,8 @@ Reference_library= Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup= +Regex= + regular_expression= Related_articles= diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index a5b2b11aa1e..26ed2bd47f8 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -991,6 +991,8 @@ Reference_library=Fichier_de_référence Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Raffine_le_super-groupe_\:_Quand_sélectionné,_afficher_les_entrées_contenues_à_la_fois_dans_ce_groupe_et_son_super-groupe +Regex= + regular_expression=Expression_régulière Related_articles=Articles_liés diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index ed3fffd8648..88362a72c8f 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -991,6 +991,8 @@ Reference_library=Basisdata_acuan Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Perbaiki_supergrup\:_Ketika_dipilih,_lihat_entri_yang_ada_di_grup_ini_dan_supergrup +Regex= + regular_expression=Ekspresi_reguler Related_articles= diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index fb18551cf9e..2cd95412174 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -991,6 +991,8 @@ Reference_library=Library_di_riferimenti Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Perfeziona_il_super-gruppo\:_Quando_selezionato,_mostra_le_voci_contenute_sia_in_questo_gruppo_sia_nel_suo_super-gruppo +Regex= + regular_expression=Espressione_regolare Related_articles= diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index 52cb6183ecc..dd6c4fb92fd 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -991,6 +991,8 @@ Reference_library=参照データベース Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=上層グループの絞り込み:このグループとその上層グループの両方に含まれている項目を表示 +Regex= + regular_expression=正規表現 Related_articles= diff --git a/src/main/resources/l10n/JabRef_nl.properties b/src/main/resources/l10n/JabRef_nl.properties index a20cfd99de9..5a3fc7a5756 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -991,6 +991,8 @@ Reference_library=Referentie_library Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Verfijn_supergroep\:_Wanneer_geselecteerd,_toon_de_entries_die_in_deze_groep_en_zijn_supergroep_zitten +Regex= + regular_expression=Regular_Expression Related_articles= diff --git a/src/main/resources/l10n/JabRef_no.properties b/src/main/resources/l10n/JabRef_no.properties index 3b799a3bf2e..8bbfee04f90 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -991,6 +991,8 @@ Reference_library=Referanselibrary Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Undergruppe\:_Vis_enheter_innehold_b\u00e5de_i_denne_gruppen_og_gruppen_over +Regex= + regular_expression=Regul\u00e6ruttrykk Related_articles= diff --git a/src/main/resources/l10n/JabRef_pt_BR.properties b/src/main/resources/l10n/JabRef_pt_BR.properties index c7420e17a5d..abe9813c733 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -991,6 +991,8 @@ Reference_library=Base_de_dados_de_referência Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Refinar_supergrupo\:_Quando_selecionado,_visualiza_referências_contidas_em_ambos_os_grupos_e_seu_supergrupo. +Regex= + regular_expression=Expressão_regular Related_articles= diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index c8730c58d5c..2d10dbe7572 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -991,6 +991,8 @@ Reference_library=БД_для_ссылки Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Детализировать_супергруппу\:_Просмотр_записей,_содержащихся_в_группе_и_ее_супергруппе_(если_выбрано) +Regex= + regular_expression=Регулярное_выражение Related_articles= diff --git a/src/main/resources/l10n/JabRef_sv.properties b/src/main/resources/l10n/JabRef_sv.properties index 5abfcd8a347..f18dc020ebe 100644 --- a/src/main/resources/l10n/JabRef_sv.properties +++ b/src/main/resources/l10n/JabRef_sv.properties @@ -991,6 +991,8 @@ Reference_library=Referensdatabas Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup= +Regex= + regular_expression=reguljärt_uttryck Related_articles= diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index addb5a748e8..db596390a57 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -991,6 +991,8 @@ Reference_library=Başvuru_veritabanı Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Supergrubu_arıt\:_Seçildiğinde,_hem_bu_grubun,_hem_de_süpergrubunun_içerdiği_girdileri_görüntüle +Regex= + regular_expression=Düzenli_İfade Related_articles= diff --git a/src/main/resources/l10n/JabRef_vi.properties b/src/main/resources/l10n/JabRef_vi.properties index 51bd9eb35cb..223a35beb5e 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -991,6 +991,8 @@ Reference_library=CSDL_tham_khảo Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Tinh_chỉnh_nhóm_lớn\:_Khi_được_chọn,_xem_các_mục_chứa_các_trong_nhóm_này_và_nhóm_lớn_của_nó +Regex= + regular_expression=Biểu_thức_chính_tắc Related_articles= diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index d6c56918b4e..cc212ff1c61 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -991,6 +991,8 @@ Reference_library=参考文献数据库 Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=提炼父分组:当分组被选中时,显示同时包含在该分组和它父分组中的记录 +Regex= + regular_expression=正则表达式 Related_articles= diff --git a/src/test/java/org/jabref/logic/formatter/FormatterTest.java b/src/test/java/org/jabref/logic/formatter/FormatterTest.java index ecb7a695b06..1fdc8231a35 100644 --- a/src/test/java/org/jabref/logic/formatter/FormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/FormatterTest.java @@ -13,6 +13,7 @@ import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; import org.jabref.logic.formatter.bibtexfields.OrdinalsToSuperscriptFormatter; +import org.jabref.logic.formatter.bibtexfields.RegexFormatter; import org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter; import org.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter; import org.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter; @@ -123,6 +124,7 @@ public static Collection instancesToTest() { new Object[]{new NormalizePagesFormatter()}, new Object[]{new OrdinalsToSuperscriptFormatter()}, new Object[]{new ProtectTermsFormatter()}, + new Object[]{new RegexFormatter()}, new Object[]{new RemoveBracesFormatter()}, new Object[]{new SentenceCaseFormatter()}, new Object[]{new TitleCaseFormatter()}, diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/RegexFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/RegexFormatterTest.java new file mode 100644 index 00000000000..b7d65f2d5b4 --- /dev/null +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RegexFormatterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.formatter.bibtexfields; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests in addition to the general tests from {@link org.jabref.logic.formatter.FormatterTest} + */ +public class RegexFormatterTest { + + private RegexFormatter formatter; + + @Before + public void setUp() { + formatter = new RegexFormatter(); + } + + @Test + public void test() { + String regexInput = "(\" \",\"-\")"; + formatter.setRegex(regexInput); + Assert.assertEquals("replace-all-spaces", formatter.format("replace all spaces")); + Assert.assertEquals("replace-spaces-{not these ones}", formatter.format("replace spaces {not these ones}")); + } + + @Test + public void formatExample() { + Assert.assertEquals("Please-replace-the-spaces", formatter.format(formatter.getExampleInput())); + } + +} From c3d4f501f1e77c9ee1ac3791e35736c4803d454e Mon Sep 17 00:00:00 2001 From: Anita Armbruster Date: Thu, 10 Aug 2017 18:12:10 +0200 Subject: [PATCH 5/9] Keep protected areas when doing regexp replacement --- CHANGELOG.md | 2 + .../jabref/logic/formatter/Formatters.java | 1 - .../bibtexfields/RegexFormatter.java | 53 ++++++++++++++++++- .../bibtexfields/RegexFormatterTest.java | 36 ++++++++++++- 4 files changed, 88 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca7162119e5..4e29a3dd866 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - If fetched article is already in database, then the entry merge dialog is shown. - An error message is now displayed if you try to create a group containing the keyword separator or if there is already a group with the same name. [#3075](https://github.com/JabRef/jabref/issues/3075) and [#1495](https://github.com/JabRef/jabref/issues/1495) - Integrity warnings are now directly displayed in the entry editor. +- We added the functionality to have `regex` as modifier. [#457](https://github.com/JabRef/jabref/issues/457) ### Fixed @@ -23,6 +24,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We readded the undo mechanism for changes in the entry editor [#2973](https://github.com/JabRef/jabref/issues/2973) - We fixed an issue where assigning an entry via drag and drop to a group caused JabRef to stop/freeze completely [#3036](https://github.com/JabRef/jabref/issues/3036) - We fixed the shortcut Ctrl+F for the search field. +- We fixed an issue where `title_case` and `capitalize` modifiers did not work with shorttitle. - We fixed an issue where the preferences could not be imported without a restart of JabRef [#3064](https://github.com/JabRef/jabref/issues/3064) - We fixed an issue where DEL, Ctrl+C, Ctrl+V and Ctrl+A in the search field triggered corresponding actions in the main table [#3067](https://github.com/JabRef/jabref/issues/3067) - We fixed an issue where JabRef freezed when editing an assigned file in the `General`-Tab [#2930, comment](https://github.com/JabRef/jabref/issues/2930#issuecomment-311050976) diff --git a/src/main/java/org/jabref/logic/formatter/Formatters.java b/src/main/java/org/jabref/logic/formatter/Formatters.java index 27540ce0089..df84c7da831 100644 --- a/src/main/java/org/jabref/logic/formatter/Formatters.java +++ b/src/main/java/org/jabref/logic/formatter/Formatters.java @@ -76,7 +76,6 @@ public static Optional getFormatterForModifier(String modifier) { String regex = modifier.substring(5); RegexFormatter.setRegex(regex); formatter = ALL.stream().filter(f -> f.getKey().equals("regex")).findAny(); - } else { formatter = ALL.stream().filter(f -> f.getKey().equals(modifier)).findAny(); } diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java index ba01035a435..c9e14cc2180 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java @@ -1,10 +1,32 @@ package org.jabref.logic.formatter.bibtexfields; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.jabref.logic.l10n.Localization; import org.jabref.model.cleanup.Formatter; public class RegexFormatter implements Formatter { + private static final Pattern PATTERN_ESCAPED_OPENING_CURLY_BRACE = Pattern.compile("\\\\\\{"); + + private static final Pattern PATTERN_ESCAPED_CLOSING_CURLY_BRACE = Pattern.compile("\\\\\\}"); + + // RegEx to match {...} + // \\ is required to have the { interpreted as character + // ? is required to disable the aggressive match + private static final Pattern PATTERN_ENCLOSED_IN_CURLY_BRACES = Pattern.compile("(\\{.*?})"); + + // Magic arbitrary unicode char, which will never appear in bibtex files + private static final String PLACEHOLDER_FOR_PROTECTED_GROUP = Character.toString('\u0A14'); + + private static final String PLACEHOLDER_FOR_OPENING_CURLY_BRACE = Character.toString('\u0A15'); + + private static final String PLACEHOLDER_FOR_CLOSING_CURLY_BRACE = Character.toString('\u0A16'); + + // stores the regex set by setRegex private static String[] regex; @Override @@ -17,12 +39,39 @@ public String getKey() { return "regex"; } + private String replaceHonoringProtectedGroups(final String input) { + Matcher matcher = PATTERN_ENCLOSED_IN_CURLY_BRACES.matcher(input); + + List replaced = new ArrayList<>(); + while (matcher.find()) { + replaced.add(matcher.group(1)); + } + String workingString = matcher.replaceAll(PLACEHOLDER_FOR_PROTECTED_GROUP); + workingString = workingString.replaceAll(RegexFormatter.regex[0], RegexFormatter.regex[1]); + + for (String r : replaced) { + workingString = workingString.replaceFirst(PLACEHOLDER_FOR_PROTECTED_GROUP, r); + } + return workingString; + } + @Override - public String format(String input) { + public String format(final String input) { if (regex == null) { return input; } - return input.replaceAll(regex[0], regex[1]); + + Matcher matcherOpeningCurlyBrace = PATTERN_ESCAPED_OPENING_CURLY_BRACE.matcher(input); + final String openingCurlyBraceReplaced = matcherOpeningCurlyBrace.replaceAll(PLACEHOLDER_FOR_OPENING_CURLY_BRACE); + + Matcher matcherClosingCurlyBrace = PATTERN_ESCAPED_CLOSING_CURLY_BRACE.matcher(openingCurlyBraceReplaced); + final String closingCurlyBraceReplaced = matcherClosingCurlyBrace.replaceAll(PLACEHOLDER_FOR_CLOSING_CURLY_BRACE); + + final String regexApplied = replaceHonoringProtectedGroups(closingCurlyBraceReplaced); + + return regexApplied + .replaceAll(PLACEHOLDER_FOR_OPENING_CURLY_BRACE, "\\\\{") + .replaceAll(PLACEHOLDER_FOR_CLOSING_CURLY_BRACE, "\\\\}"); } @Override diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/RegexFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/RegexFormatterTest.java index b7d65f2d5b4..4c85a519f90 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RegexFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RegexFormatterTest.java @@ -17,13 +17,47 @@ public void setUp() { } @Test - public void test() { + public void spacesReplacedCorrectly() { String regexInput = "(\" \",\"-\")"; formatter.setRegex(regexInput); Assert.assertEquals("replace-all-spaces", formatter.format("replace all spaces")); + } + + @Test + public void protectedSpacesNotReplacedInSingleProtectedBlock() { + String regexInput = "(\" \",\"-\")"; + formatter.setRegex(regexInput); Assert.assertEquals("replace-spaces-{not these ones}", formatter.format("replace spaces {not these ones}")); } + @Test + public void protectedSpacesNotReplacedInTwoProtectedBlocks() { + String regexInput = "(\" \",\"-\")"; + formatter.setRegex(regexInput); + Assert.assertEquals("replace-spaces-{not these ones}-{or these ones}-but-these-ones", formatter.format("replace spaces {not these ones} {or these ones} but these ones")); + } + + @Test + public void escapedBracesAreNotReplaced() { + String regexInput = "(\" \",\"-\")"; + formatter.setRegex(regexInput); + Assert.assertEquals("replace-spaces-\\{-these-ones\\}-and-these-ones", formatter.format("replace spaces \\{ these ones\\} and these ones")); + } + + @Test + public void escapedBracesAreNotReplacedInTwoCases() { + String regexInput = "(\" \",\"-\")"; + formatter.setRegex(regexInput); + Assert.assertEquals("replace-spaces-\\{-these-ones\\},-these-ones,-and-\\{-these-ones\\}", formatter.format("replace spaces \\{ these ones\\}, these ones, and \\{ these ones\\}")); + } + + @Test + public void escapedBracesAreNotReplacedAndProtectionStillWorks() { + String regexInput = "(\" \",\"-\")"; + formatter.setRegex(regexInput); + Assert.assertEquals("replace-spaces-{not these ones},-these-ones,-and-\\{-these-ones\\}", formatter.format("replace spaces {not these ones}, these ones, and \\{ these ones\\}")); + } + @Test public void formatExample() { Assert.assertEquals("Please-replace-the-spaces", formatter.format(formatter.getExampleInput())); From be858479675695f475b16bd897fff01135c30e6c Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Thu, 10 Aug 2017 19:18:33 +0200 Subject: [PATCH 6/9] Add missing localisations --- src/main/resources/l10n/JabRef_da.properties | 2 ++ src/main/resources/l10n/JabRef_de.properties | 2 ++ src/main/resources/l10n/JabRef_el.properties | 4 ++++ src/main/resources/l10n/JabRef_en.properties | 1 - src/main/resources/l10n/JabRef_es.properties | 2 ++ src/main/resources/l10n/JabRef_fa.properties | 2 ++ src/main/resources/l10n/JabRef_fr.properties | 2 ++ src/main/resources/l10n/JabRef_in.properties | 2 ++ src/main/resources/l10n/JabRef_it.properties | 2 ++ src/main/resources/l10n/JabRef_ja.properties | 2 ++ src/main/resources/l10n/JabRef_nl.properties | 2 ++ src/main/resources/l10n/JabRef_no.properties | 2 ++ src/main/resources/l10n/JabRef_pt_BR.properties | 2 ++ src/main/resources/l10n/JabRef_ru.properties | 2 ++ src/main/resources/l10n/JabRef_sv.properties | 2 ++ src/main/resources/l10n/JabRef_tr.properties | 2 ++ src/main/resources/l10n/JabRef_vi.properties | 2 ++ src/main/resources/l10n/JabRef_zh.properties | 2 ++ 18 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/resources/l10n/JabRef_da.properties b/src/main/resources/l10n/JabRef_da.properties index 7030d0ea665..4906c2bd62e 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=Stien_behøver_ikke_at_være_p Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Tilføj_en_kompileret_Importer-klasse_fra_en_ZIP-fil. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=ZIP-filen_behøver_ikke_at_være_i_din_classpath. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group= Add_from_folder=Tilføj_fra_mappe diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index 68d91e224ef..df3b534a778 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=Das_Verzeichnis_muss_nicht_im_K Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Füge_eine_(kompilierte)_externe_Importer_Klasse_aus_Verzeichnis_hinzu. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=Das_Verzeichnis_muss_nicht_im_Klassenpfad_von_JabRef_enthalten_sein. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group=Ausgewählte_Einträge_zu_dieser_Gruppe_hinzufügen Add_from_folder=Aus_Klassenpfad_hinzufügen diff --git a/src/main/resources/l10n/JabRef_el.properties b/src/main/resources/l10n/JabRef_el.properties index c720bd96c8d..dfa73792b77 100644 --- a/src/main/resources/l10n/JabRef_el.properties +++ b/src/main/resources/l10n/JabRef_el.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=The_path_need_not_be_on_the_cla Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.= The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group= Add_from_folder=Προσθήκη_από_φάκελο @@ -950,6 +952,8 @@ Reference_library= Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup +Regex= + regular_expression=regular_expression Related_articles= diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 3afc0eae327..b58bb37f5cd 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -53,7 +53,6 @@ The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=The_ZIP-archive_need_not Add_a_regular_expression_for_the_key_pattern.=Add_a_regular_expression_for_the_key_pattern. -Add_entry_selection_to_this_group=Add_entry_selection_to_this_group Add_selected_entries_to_this_group=Add_selected_entries_to_this_group Add_from_folder=Add_from_folder diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index 0822515f3e7..a002b6889f2 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=La_ruta_no_debe_estar_en_la_cla Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Añadir_una_clase_personalizada_(compilada)_Importer_desde_un_archivo_ZIP. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=El_archivo_ZIP_no_tiene_por_qué_estar_en_la_classpath_de_JabRef. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group=Añadir_entradas_seleccionadas_a_este_grupo Add_from_folder=Añadir_desde_carpeta diff --git a/src/main/resources/l10n/JabRef_fa.properties b/src/main/resources/l10n/JabRef_fa.properties index b1d0e57c965..d794fc0209e 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.= Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.= The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.= +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group= Add_from_folder= diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index d03aab5fecb..5ecf6d9985e 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=Le_chemin_n'a_pas_besoin_d'êtr Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Ajouter_une_classe_Importer_personnalisée_(compilée)_à_partir_d'une_archive_ZIP. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=L'archive_ZIP_n'a_pas_besoin_d'être_dans_le_chemin_de_classe_de_JabRef. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group=Ajouter_les_entrées_sélectionnées_à_ce_groupe Add_from_folder=Ajouter_à_partir_du_répertoire diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index 2b83426d800..b46b567afb7 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=Lokasi_tidak_harus_pada_lokasi_ Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Tambah_suaian_kelas_Importer_dari_arsip_ZIP. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=Lokasi_arsip_ZIP_tidak_harus_dalam_lokasi_kelas_JabRef. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group= Add_from_folder=Tambah_dari_folder diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index 07be08d43b3..5a11cbe34c5 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=Il_percorso_non_deve_necessaria Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Aggiungi_una_classe_Importer_personalizzata_(compilata)_da_un_archivio_ZIP. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=L'archivio_ZIP_non_deve_necessariamente_essere_nel_classpath_di_JabRef. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group=Aggiungi_le_voci_selezionate_a_questo_gruppo Add_from_folder=Aggiungi_da_una_cartella diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index 428b4b7a0a5..0479763bf12 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=このパスは、JabRefのク Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=(コンパイルした)ユーザー定義ImportFormatクラスをZIP書庫から追加します。 The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=このZIP書庫は、JabRefのクラスパスにあるとは限りません。 +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group= Add_from_folder=フォルダから追加 diff --git a/src/main/resources/l10n/JabRef_nl.properties b/src/main/resources/l10n/JabRef_nl.properties index 9428327b9c9..212474ed37f 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=Het_pad_moet_niet_in_het_classp Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Voeg_een_(gecompileerde)_externe_Importer_klasse_van_een_ZIP-archief_toe. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=Het_pad_moet_niet_in_het_classpath_van_JabRef_staan. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group= Add_from_folder=Voeg_toe_uit_map diff --git a/src/main/resources/l10n/JabRef_no.properties b/src/main/resources/l10n/JabRef_no.properties index 546551cc613..5a7735e326a 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=Stien_trenger_ikke_\u00e5_v\u00 Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Legg_til_en_(kompilert)_egendefinert_Importer-klasse_fra_en_zip-fil. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=ZIP-filen_trenger_ikke_\u00e5_v\u00e6re_p\u00e5_JabRefs_classpath. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group= Add_from_folder=Legg_til_fra_mappe diff --git a/src/main/resources/l10n/JabRef_pt_BR.properties b/src/main/resources/l10n/JabRef_pt_BR.properties index 54dcb9bc686..edd37622e74 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=O_caminho_não_precisa_estar_no Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Adicionar_uma_classe_Importer_customizada_(compilada)_a_partir_de_um_arquivo_zip. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=O_arquivo_zip_não_precisa_estar_no_classpath_do_JabRef. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group= Add_from_folder=Adicionar_a_partir_de_uma_pasta diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index 4db1bdcb9dd..31a35fcfa67 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=Путь_может_не_сов Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Добавить_(скомпил.)_пользовательский_класс_Importer_из_ZIP-архива. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=ZIP-архив_может_не_совпадать_с_путем_классов_JabRef. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group= Add_from_folder=Добавить_из_папки diff --git a/src/main/resources/l10n/JabRef_sv.properties b/src/main/resources/l10n/JabRef_sv.properties index 91a6f8e2d85..008839300ee 100644 --- a/src/main/resources/l10n/JabRef_sv.properties +++ b/src/main/resources/l10n/JabRef_sv.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.= Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Lägg_till_en_(kompilerad)_Importer-klass_från_en_zip-fil. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.= +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group= Add_from_folder=Lägg_till_från_mapp diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index f5f2ddc1db1..ab3c5cb2040 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=Yolun_JabRef'in_sınıf_yolunda Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Bir_ZIP_arşivinden_(derlenmiş)_özel_İçeAlmaBiçemi_sınıfı_ekle. The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=Yolun_JabRef'in_sınıf_yolunda_olması_gerekmez. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group=Seçili_girdileri_bu_gruba_ekle Add_from_folder=Klasörden_ekle diff --git a/src/main/resources/l10n/JabRef_vi.properties b/src/main/resources/l10n/JabRef_vi.properties index b7772ef114c..afdad75a714 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=Đường_dẫn_không_được Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Thêm_một_lớp_ĐịnhdạngNhập_tùy_biến_(được_biên_dịch)_từ_một_tập_tin-zip._ The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=Tập_tin-zip_không_được_trùng_với_đường_dẫn_lớp_của_JabRef. +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group= Add_from_folder=Thêm_từ_thư_mục diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index f9b430f937f..af23b6b10e1 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -51,6 +51,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=该路径不需要在_JabRef_ Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=从一个_ZIP_压缩包中添加(编译好的)自定义导入类。 The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=该_ZIP_压缩包不需要在_JabRef_的_classpath_下。 +Add_a_regular_expression_for_the_key_pattern.= + Add_selected_entries_to_this_group=添加选定记录到该组 Add_from_folder=从文件夹中添加 From 66b888fa9db06f042cefbfcacb064f408149d4a1 Mon Sep 17 00:00:00 2001 From: Anita Armbruster Date: Fri, 11 Aug 2017 14:05:41 +0200 Subject: [PATCH 7/9] Fix Codacy "Avoid reassigning parameters" issue. --- .../jabref/logic/formatter/bibtexfields/RegexFormatter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java index c9e14cc2180..f7574d9b839 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java @@ -86,8 +86,9 @@ public String getExampleInput() { public static void setRegex(String rex) { // formatting is like ("exp1","exp2"), we want to remove (" and ") - rex = rex.substring(2, rex.length() - 2); - String[] parts = rex.split("\",\""); + String rexToSet = rex; + rexToSet = rexToSet.substring(2, rexToSet.length() - 2); + String[] parts = rexToSet.split("\",\""); regex = parts; } From ae829f1a22eb6bc7db9c72496b901dad6670dd26 Mon Sep 17 00:00:00 2001 From: Anita Armbruster Date: Tue, 15 Aug 2017 10:07:51 +0200 Subject: [PATCH 8/9] Add constants and update localzation --- src/main/java/org/jabref/logic/formatter/Formatters.java | 4 +++- .../logic/formatter/bibtexfields/RegexFormatter.java | 7 +++++-- src/main/resources/l10n/JabRef_da.properties | 2 -- src/main/resources/l10n/JabRef_de.properties | 2 -- src/main/resources/l10n/JabRef_el.properties | 2 -- src/main/resources/l10n/JabRef_en.properties | 2 -- src/main/resources/l10n/JabRef_es.properties | 2 -- src/main/resources/l10n/JabRef_fa.properties | 2 -- src/main/resources/l10n/JabRef_fr.properties | 2 -- src/main/resources/l10n/JabRef_in.properties | 2 -- src/main/resources/l10n/JabRef_it.properties | 2 -- src/main/resources/l10n/JabRef_ja.properties | 2 -- src/main/resources/l10n/JabRef_nl.properties | 2 -- src/main/resources/l10n/JabRef_no.properties | 2 -- src/main/resources/l10n/JabRef_pt_BR.properties | 2 -- src/main/resources/l10n/JabRef_ru.properties | 2 -- src/main/resources/l10n/JabRef_sv.properties | 2 -- src/main/resources/l10n/JabRef_tr.properties | 2 -- src/main/resources/l10n/JabRef_vi.properties | 2 -- src/main/resources/l10n/JabRef_zh.properties | 2 -- 20 files changed, 8 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/jabref/logic/formatter/Formatters.java b/src/main/java/org/jabref/logic/formatter/Formatters.java index df84c7da831..c21ac689122 100644 --- a/src/main/java/org/jabref/logic/formatter/Formatters.java +++ b/src/main/java/org/jabref/logic/formatter/Formatters.java @@ -65,6 +65,8 @@ public class Formatters { public static final List ALL = new ArrayList<>(); + private static final int LENGTH_OF_REGEX_PREFIX = 5; + private Formatters() { } @@ -73,7 +75,7 @@ public static Optional getFormatterForModifier(String modifier) { Optional formatter; if (modifier.matches("regex.*")) { - String regex = modifier.substring(5); + String regex = modifier.substring(LENGTH_OF_REGEX_PREFIX); RegexFormatter.setRegex(regex); formatter = ALL.stream().filter(f -> f.getKey().equals("regex")).findAny(); } else { diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java index f7574d9b839..5696c23483d 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -26,12 +27,13 @@ public class RegexFormatter implements Formatter { private static final String PLACEHOLDER_FOR_CLOSING_CURLY_BRACE = Character.toString('\u0A16'); + private static final int REMOVE_OUTER_QUOTES = 2; // stores the regex set by setRegex private static String[] regex; @Override public String getName() { - return Localization.lang("Regex"); + return Localization.lang("regular_expression"); } @Override @@ -57,6 +59,7 @@ private String replaceHonoringProtectedGroups(final String input) { @Override public String format(final String input) { + Objects.requireNonNull(input); if (regex == null) { return input; } @@ -87,7 +90,7 @@ public String getExampleInput() { public static void setRegex(String rex) { // formatting is like ("exp1","exp2"), we want to remove (" and ") String rexToSet = rex; - rexToSet = rexToSet.substring(2, rexToSet.length() - 2); + rexToSet = rexToSet.substring(REMOVE_OUTER_QUOTES, rexToSet.length() - REMOVE_OUTER_QUOTES); String[] parts = rexToSet.split("\",\""); regex = parts; } diff --git a/src/main/resources/l10n/JabRef_da.properties b/src/main/resources/l10n/JabRef_da.properties index 4906c2bd62e..e33a26c6035 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -952,8 +952,6 @@ Reference_library=Referencelibrary Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Undergruppe\:_Vis_poster_indeholdt_både_i_denne_gruppe_og_gruppe_over -Regex= - regular_expression=Regulærudtryk Related_articles= diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index df3b534a778..446009f9fcd 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -952,8 +952,6 @@ Reference_library=Referenz-Bibliothek Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Obergruppe_einbeziehen\:_Einträge_aus_dieser_Gruppe_und_ihrer_übergeordneten_Gruppe_anzeigen -Regex= - regular_expression=Regulärer_Ausdruck Related_articles=ähnliche_Dokumente diff --git a/src/main/resources/l10n/JabRef_el.properties b/src/main/resources/l10n/JabRef_el.properties index dfa73792b77..fcda3898416 100644 --- a/src/main/resources/l10n/JabRef_el.properties +++ b/src/main/resources/l10n/JabRef_el.properties @@ -952,8 +952,6 @@ Reference_library= Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup -Regex= - regular_expression=regular_expression Related_articles= diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index b58bb37f5cd..4fa4b7aa5ce 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -952,8 +952,6 @@ Reference_library=Reference_library Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup -Regex=Regex - regular_expression=regular_expression Related_articles=Related_articles diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index a002b6889f2..d728f351ef4 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -952,8 +952,6 @@ Reference_library=Biblioteca_de_referencia Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Refinar_supergrupo\:_Ver_entradas_contenidas_en_este_grupo_y_sus_subgrupos_cuando_estén_seleccionadas -Regex= - regular_expression=Expresión_Regular Related_articles=Artículos_relacionados diff --git a/src/main/resources/l10n/JabRef_fa.properties b/src/main/resources/l10n/JabRef_fa.properties index d794fc0209e..69d8c4b81d6 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -952,8 +952,6 @@ Reference_library= Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup= -Regex= - regular_expression= Related_articles= diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index 5ecf6d9985e..81d389c341e 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -952,8 +952,6 @@ Reference_library=Fichier_de_référence Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Raffine_le_super-groupe_\:_Quand_sélectionné,_afficher_les_entrées_contenues_à_la_fois_dans_ce_groupe_et_son_super-groupe -Regex= - regular_expression=Expression_régulière Related_articles=Articles_liés diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index b46b567afb7..1421d85a28c 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -952,8 +952,6 @@ Reference_library=Basisdata_acuan Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Perbaiki_supergrup\:_Ketika_dipilih,_lihat_entri_yang_ada_di_grup_ini_dan_supergrup -Regex= - regular_expression=Ekspresi_reguler Related_articles= diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index 5a11cbe34c5..44d83d9d210 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -952,8 +952,6 @@ Reference_library=Libreria_di_riferimenti Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Perfeziona_il_super-gruppo\:_Quando_selezionato,_mostra_le_voci_contenute_sia_in_questo_gruppo_sia_nel_suo_super-gruppo -Regex= - regular_expression=Espressione_regolare Related_articles=Articoli_correlati diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index 0479763bf12..e1d884fa2ce 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -952,8 +952,6 @@ Reference_library=参照データベース Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=上層グループの絞り込み:このグループとその上層グループの両方に含まれている項目を表示 -Regex= - regular_expression=正規表現 Related_articles= diff --git a/src/main/resources/l10n/JabRef_nl.properties b/src/main/resources/l10n/JabRef_nl.properties index 212474ed37f..b1ca0f6dbe2 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -952,8 +952,6 @@ Reference_library=Referentie_library Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Verfijn_supergroep\:_Wanneer_geselecteerd,_toon_de_entries_die_in_deze_groep_en_zijn_supergroep_zitten -Regex= - regular_expression=Regular_Expression Related_articles= diff --git a/src/main/resources/l10n/JabRef_no.properties b/src/main/resources/l10n/JabRef_no.properties index 5a7735e326a..8282809df9b 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -952,8 +952,6 @@ Reference_library=Referanselibrary Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Undergruppe\:_Vis_enheter_innehold_b\u00e5de_i_denne_gruppen_og_gruppen_over -Regex= - regular_expression=Regul\u00e6ruttrykk Related_articles= diff --git a/src/main/resources/l10n/JabRef_pt_BR.properties b/src/main/resources/l10n/JabRef_pt_BR.properties index edd37622e74..669d0c1da67 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -952,8 +952,6 @@ Reference_library=Base_de_dados_de_referência Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Refinar_supergrupo\:_Quando_selecionado,_visualiza_referências_contidas_em_ambos_os_grupos_e_seu_supergrupo. -Regex= - regular_expression=Expressão_regular Related_articles= diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index 31a35fcfa67..ef66c1f6d9e 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -952,8 +952,6 @@ Reference_library=БД_для_ссылки Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Детализировать_супергруппу\:_Просмотр_записей,_содержащихся_в_группе_и_ее_супергруппе_(если_выбрано) -Regex= - regular_expression=Регулярное_выражение Related_articles= diff --git a/src/main/resources/l10n/JabRef_sv.properties b/src/main/resources/l10n/JabRef_sv.properties index 008839300ee..7a3f81935f6 100644 --- a/src/main/resources/l10n/JabRef_sv.properties +++ b/src/main/resources/l10n/JabRef_sv.properties @@ -952,8 +952,6 @@ Reference_library=Referensdatabas Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup= -Regex= - regular_expression=reguljärt_uttryck Related_articles= diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index ab3c5cb2040..159c9b2c096 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -952,8 +952,6 @@ Reference_library=Başvuru_veritabanı Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Supergrubu_arıt\:_Seçildiğinde,_hem_bu_grubun,_hem_de_süpergrubunun_içerdiği_girdileri_görüntüle -Regex= - regular_expression=Düzenli_İfade Related_articles=İlgili_makaleler diff --git a/src/main/resources/l10n/JabRef_vi.properties b/src/main/resources/l10n/JabRef_vi.properties index afdad75a714..ebfc8efef59 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -952,8 +952,6 @@ Reference_library=CSDL_tham_khảo Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Tinh_chỉnh_nhóm_lớn\:_Khi_được_chọn,_xem_các_mục_chứa_các_trong_nhóm_này_và_nhóm_lớn_của_nó -Regex= - regular_expression=Biểu_thức_chính_tắc Related_articles= diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index af23b6b10e1..4a01101ba3d 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -952,8 +952,6 @@ Reference_library=参考文献文献库 Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=提炼父分组:当分组被选中时,显示同时包含在该分组和它父分组中的记录 -Regex= - regular_expression=正则表达式 Related_articles=相关文章 From a5b2db084df9bf71d97ce81c38a3732ca6440d14 Mon Sep 17 00:00:00 2001 From: Anita Armbruster Date: Wed, 16 Aug 2017 11:55:08 +0200 Subject: [PATCH 9/9] Change naming and declaration of constants --- .../java/org/jabref/logic/formatter/Formatters.java | 4 +++- .../logic/formatter/bibtexfields/RegexFormatter.java | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/logic/formatter/Formatters.java b/src/main/java/org/jabref/logic/formatter/Formatters.java index c21ac689122..9f682ae5130 100644 --- a/src/main/java/org/jabref/logic/formatter/Formatters.java +++ b/src/main/java/org/jabref/logic/formatter/Formatters.java @@ -65,7 +65,9 @@ public class Formatters { public static final List ALL = new ArrayList<>(); - private static final int LENGTH_OF_REGEX_PREFIX = 5; + private static final String REGEX = "regex"; + + private static final int LENGTH_OF_REGEX_PREFIX = REGEX.length(); private Formatters() { } diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java index 5696c23483d..3ad3b763676 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java @@ -27,7 +27,14 @@ public class RegexFormatter implements Formatter { private static final String PLACEHOLDER_FOR_CLOSING_CURLY_BRACE = Character.toString('\u0A16'); - private static final int REMOVE_OUTER_QUOTES = 2; + private static final String QUOTE_AND_OPENING_BRACE = "\"("; + + private static final int LENGTH_OF_QUOTE_AND_OPENING_BRACE = QUOTE_AND_OPENING_BRACE.length(); + + private static final String CLOSING_BRACE_AND_QUOTE = ")\""; + + private static final int LENGTH_OF_CLOSING_BRACE_AND_QUOTE = CLOSING_BRACE_AND_QUOTE.length(); + // stores the regex set by setRegex private static String[] regex; @@ -90,7 +97,7 @@ public String getExampleInput() { public static void setRegex(String rex) { // formatting is like ("exp1","exp2"), we want to remove (" and ") String rexToSet = rex; - rexToSet = rexToSet.substring(REMOVE_OUTER_QUOTES, rexToSet.length() - REMOVE_OUTER_QUOTES); + rexToSet = rexToSet.substring(LENGTH_OF_QUOTE_AND_OPENING_BRACE, rexToSet.length() - LENGTH_OF_CLOSING_BRACE_AND_QUOTE); String[] parts = rexToSet.split("\",\""); regex = parts; }