From 48ba0fea47cb0ebb13948bc21b9d9d4f0ad3ebd5 Mon Sep 17 00:00:00 2001 From: bartsch-dev Date: Fri, 7 Oct 2016 13:07:30 +0200 Subject: [PATCH] Remove some UnicodeToLatex uses (#2132) * remove some UnicodeToLatex uses * readd removeBracesFormatter --- .../jabref/gui/search/SearchResultFrame.java | 5 +---- .../logic/importer/fetcher/CrossRef.java | 15 ++------------- .../sf/jabref/logic/msbib/MSBibConverter.java | 18 ++++++------------ .../search/rules/ContainBasedSearchRule.java | 3 --- .../search/rules/RegexBasedSearchRule.java | 3 --- 5 files changed, 9 insertions(+), 35 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/search/SearchResultFrame.java b/src/main/java/net/sf/jabref/gui/search/SearchResultFrame.java index baca400c2274..e7ca1894fb06 100644 --- a/src/main/java/net/sf/jabref/gui/search/SearchResultFrame.java +++ b/src/main/java/net/sf/jabref/gui/search/SearchResultFrame.java @@ -54,7 +54,6 @@ import net.sf.jabref.logic.bibtex.comparator.EntryComparator; import net.sf.jabref.logic.bibtex.comparator.FieldComparator; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.layout.format.LatexToUnicodeFormatter; import net.sf.jabref.logic.search.SearchQuery; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; @@ -613,9 +612,7 @@ public Object getColumnValue(BibEntry entry, int column) { } else { String field = FIELDS[column - PAD]; - - String fieldContent = entry.getField(field).orElse(""); - fieldContent = new LatexToUnicodeFormatter().format(fieldContent); + String fieldContent = entry.getLatexFreeField(field).orElse(""); if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.PERSON_NAMES)) { // For name fields, tap into a MainTableFormat instance and use diff --git a/src/main/java/net/sf/jabref/logic/importer/fetcher/CrossRef.java b/src/main/java/net/sf/jabref/logic/importer/fetcher/CrossRef.java index 29c7142894a6..19a472ada5b4 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fetcher/CrossRef.java +++ b/src/main/java/net/sf/jabref/logic/importer/fetcher/CrossRef.java @@ -5,7 +5,6 @@ import java.util.Optional; import net.sf.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter; -import net.sf.jabref.logic.layout.format.LatexToUnicodeFormatter; import net.sf.jabref.logic.util.DOI; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; @@ -28,6 +27,7 @@ */ public class CrossRef { private static final Log LOGGER = LogFactory.getLog(CrossRef.class); + private static final RemoveBracesFormatter REMOVE_BRACES_FORMATTER = new RemoveBracesFormatter(); private static final String API_URL = "http://api.crossref.org"; private static final Levenshtein METRIC_DISTANCE = new Levenshtein(); @@ -85,8 +85,7 @@ private static String enhanceQuery(String query, BibEntry entry) { } private static boolean checkValidity(BibEntry entry, JSONArray result) { - // TODO: use latex-free version instead in the future - final String entryTitle = entry.getField(FieldName.TITLE).map(CrossRef::removeLaTeX).orElse(""); + final String entryTitle = REMOVE_BRACES_FORMATTER.format(entry.getLatexFreeField(FieldName.TITLE).orElse("")); // currently only title-based // title: [ "How the Mind Hurts and Heals the Body." ] @@ -114,16 +113,6 @@ private static boolean checkValidity(BibEntry entry, JSONArray result) { } } - private static String removeLaTeX(String text) { - String result; - // remove braces - result = new RemoveBracesFormatter().format(text); - // convert to unicode - result = new LatexToUnicodeFormatter().format(result); - - return result; - } - private static double editDistanceIgnoreCase(String a, String b) { // TODO: locale is dependent on the language of the strings?! return METRIC_DISTANCE.distance(a.toLowerCase(Locale.ENGLISH), b.toLowerCase(Locale.ENGLISH)); diff --git a/src/main/java/net/sf/jabref/logic/msbib/MSBibConverter.java b/src/main/java/net/sf/jabref/logic/msbib/MSBibConverter.java index 1ebd393f6b9b..247e4e07544c 100644 --- a/src/main/java/net/sf/jabref/logic/msbib/MSBibConverter.java +++ b/src/main/java/net/sf/jabref/logic/msbib/MSBibConverter.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.Locale; -import net.sf.jabref.logic.layout.format.LatexToUnicodeFormatter; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; @@ -24,7 +23,7 @@ public static MSBibEntry convert(BibEntry entry) { for (String field : entry.getFieldNames()) { // clean field - String unicodeField = removeLaTeX(entry.getField(field).orElse("")); + String unicodeField = entry.getLatexFreeField(field).orElse(""); if (MSBibMapping.getMSBibField(field) != null) { result.fields.put(MSBibMapping.getMSBibField(field), unicodeField); @@ -104,8 +103,8 @@ public static MSBibEntry convert(BibEntry entry) { result.publicationTitle = entry.getField(FieldName.TITLE).orElse(null); } - entry.getField(FieldName.AUTHOR).ifPresent(authors -> result.authors = getAuthors(authors)); - entry.getField(FieldName.EDITOR).ifPresent(editors -> result.editors = getAuthors(editors)); + entry.getLatexFreeField(FieldName.AUTHOR).ifPresent(authors -> result.authors = getAuthors(authors)); + entry.getLatexFreeField(FieldName.EDITOR).ifPresent(editors -> result.editors = getAuthors(editors)); return result; } @@ -113,20 +112,15 @@ public static MSBibEntry convert(BibEntry entry) { private static List getAuthors(String authors) { List result = new ArrayList<>(); - String cleanAuthors = removeLaTeX(authors); - - if (cleanAuthors.toUpperCase(Locale.ENGLISH).contains(" AND ")) { - String[] names = cleanAuthors.split(" (?i)and "); + if (authors.toUpperCase(Locale.ENGLISH).contains(" AND ")) { + String[] names = authors.split(" (?i)and "); for (String name : names) { result.add(new PersonName(name)); } } else { - result.add(new PersonName(cleanAuthors)); + result.add(new PersonName(authors)); } return result; } - private static String removeLaTeX(String text) { - return new LatexToUnicodeFormatter().format(text); - } } diff --git a/src/main/java/net/sf/jabref/model/search/rules/ContainBasedSearchRule.java b/src/main/java/net/sf/jabref/model/search/rules/ContainBasedSearchRule.java index 9d298da37163..22b0f806d8fd 100644 --- a/src/main/java/net/sf/jabref/model/search/rules/ContainBasedSearchRule.java +++ b/src/main/java/net/sf/jabref/model/search/rules/ContainBasedSearchRule.java @@ -4,15 +4,12 @@ import java.util.List; import net.sf.jabref.model.entry.BibEntry; -import net.sf.jabref.model.strings.LatexToUnicode; /** * Search rule for contain-based search. */ public class ContainBasedSearchRule implements SearchRule { - private static final LatexToUnicode LATEX_TO_UNICODE_FORMATTER = new LatexToUnicode(); - private final boolean caseSensitive; public ContainBasedSearchRule(boolean caseSensitive) { diff --git a/src/main/java/net/sf/jabref/model/search/rules/RegexBasedSearchRule.java b/src/main/java/net/sf/jabref/model/search/rules/RegexBasedSearchRule.java index a5677e03a2d6..e89c394c09ec 100644 --- a/src/main/java/net/sf/jabref/model/search/rules/RegexBasedSearchRule.java +++ b/src/main/java/net/sf/jabref/model/search/rules/RegexBasedSearchRule.java @@ -6,15 +6,12 @@ import java.util.regex.PatternSyntaxException; import net.sf.jabref.model.entry.BibEntry; -import net.sf.jabref.model.strings.LatexToUnicode; /** * Search rule for regex-based search. */ public class RegexBasedSearchRule implements SearchRule { - private static final LatexToUnicode LATEX_TO_UNICODE_FORMATTER = new LatexToUnicode(); - private final boolean caseSensitive; public RegexBasedSearchRule(boolean caseSensitive) {