Skip to content

Commit

Permalink
Add NormalizeEnDashesFormatter (#4045)
Browse files Browse the repository at this point in the history
* Add NormalizeEnDashesFormatter
* Adapt to new Formatter hiearchy
* Add missing localization keys
  • Loading branch information
koppor authored and stefan-kolb committed May 25, 2018
1 parent cab2692 commit b029c72
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We added a fetcher based on RFC-IDs. [#3971](https://github.com/JabRef/jabref/issues/3971)
- We changed the implementation of the `[shorttitle]` key pattern. It now removes small words like `a`, `an`, `on`, `the` etc. Refer to the help page for a complete overview. [Feature request in the forum](http://discourse.jabref.org/t/jabref-differences-in-shorttitle-between-versions-3-8-1-and-4-not-discounting-the-a-an-of-in-titles/1147)
- We added a formatter for adding braces around the `title` field. E.g., `title = {ExamPle}` becomes `title = {{ExamPle}}`, which prevents BibTeX to convert it to lower case. You can use it at the [cleanup entries](http://help.jabref.org/en/CleanupEntries) functionality.
- We added a formatter to ensure correct en dashes in the `title` field. E.g., `title = {Example - illustrative}` becomes `title = {Example -- illustrative}`.
- We streamlined the defaults for a [cleanup of entries](http://help.jabref.org/en/CleanupEntries) in the case of BibTeX.

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/logic/formatter/Formatters.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.jabref.logic.formatter.bibtexfields.HtmlToUnicodeFormatter;
import org.jabref.logic.formatter.bibtexfields.LatexCleanupFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizeEnDashesFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class Formatters {
new LatexCleanupFormatter(),
new MinifyNameListFormatter(),
new NormalizeDateFormatter(),
new NormalizeEnDashesFormatter(),
new NormalizeMonthFormatter(),
new NormalizeNamesFormatter(),
new NormalizePagesFormatter(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.jabref.logic.formatter.bibtexfields;

import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class NormalizeEnDashesFormatter extends Formatter {

@Override
public String getName() {
return Localization.lang("Normalize en dashes");
}

@Override
public String getKey() {
return "normalize_en_dashes";
}

@Override
public String format(String value) {
return value.replaceAll(" - ", " -- ");
}

@Override
public String getDescription() {
return Localization.lang("Normalizes the en dashes.");
}

@Override
public String getExampleInput() {
return "Winery - A Modeling Tool for TOSCA-based Cloud Applications";
}
}
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1957,13 +1957,15 @@ LaTeX\ to\ Unicode=LaTeX to Unicode
Lower\ case=Lower case
Minify\ list\ of\ person\ names=Minify list of person names
Normalize\ date=Normalize date
Normalize\ en\ dashes=Normalize en dashes
Normalize\ month=Normalize month
Normalize\ month\ to\ BibTeX\ standard\ abbreviation.=Normalize month to BibTeX standard abbreviation.
Normalize\ names\ of\ persons=Normalize names of persons
Normalize\ page\ numbers=Normalize page numbers
Normalize\ pages\ to\ BibTeX\ standard.=Normalize pages to BibTeX standard.
Normalizes\ lists\ of\ persons\ to\ the\ BibTeX\ standard.=Normalizes lists of persons to the BibTeX standard.
Normalizes\ the\ date\ to\ ISO\ date\ format.=Normalizes the date to ISO date format.
Normalizes\ the\ en\ dashes.=Normalizes the en dashes.
Ordinals\ to\ LaTeX\ superscript=Ordinals to LaTeX superscript
Protect\ terms=Protect terms
Add\ enclosing\ braces=Add enclosing braces
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.jabref.logic.formatter.bibtexfields;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Tests in addition to the general tests from {@link org.jabref.logic.formatter.FormatterTest}
*/
public class NormalizeEnDashesFormatterTest {

private NormalizeEnDashesFormatter formatter;

@BeforeEach
public void setUp() {
formatter = new NormalizeEnDashesFormatter();
}

@Test
public void formatExample() {
assertEquals("Winery -- A Modeling Tool for TOSCA-based Cloud Applications", formatter.format(formatter.getExampleInput()));
}

@Test
public void formatExampleOfChangelog() {
assertEquals("Example -- illustrative", formatter.format("Example - illustrative"));
}

@Test
public void dashesWithinWordsAreKept() {
assertEquals("Example-illustrative", formatter.format("Example-illustrative"));
}

@Test
public void dashesPreceededByASpaceAreKept() {
assertEquals("Example -illustrative", formatter.format("Example -illustrative"));
}

@Test
public void dashesFollowedByASpaceAreKept() {
assertEquals("Example- illustrative", formatter.format("Example- illustrative"));
}

@Test
public void dashAtTheBeginningIsKept() {
assertEquals("- illustrative", formatter.format("- illustrative"));
}

@Test
public void dashAtTheEndIsKept() {
assertEquals("Example-", formatter.format("Example-"));
}
}

0 comments on commit b029c72

Please sign in to comment.