-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3291 from JabRef/rm-newline-annotation
- Loading branch information
Showing
25 changed files
with
142 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.jabref.logic.formatter.bibtexfields; | ||
|
||
import java.util.Objects; | ||
import java.util.regex.Pattern; | ||
|
||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.cleanup.Formatter; | ||
|
||
/** | ||
* Removes all hyphenated line breaks in the string. | ||
*/ | ||
public class RemoveHyphenatedNewlinesFormatter implements Formatter { | ||
private static final Pattern HYPHENATED_WORDS = Pattern.compile("(-\r\n|-\n|-\r)"); | ||
|
||
@Override | ||
public String getName() { | ||
return Localization.lang("Remove hyphenated line breaks"); | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return "remove_hyphenated_newlines"; | ||
} | ||
|
||
@Override | ||
public String format(String value) { | ||
Objects.requireNonNull(value); | ||
|
||
value = HYPHENATED_WORDS.matcher(value).replaceAll(""); | ||
return value.trim(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return Localization.lang("Removes all hyphenated line breaks in the field content."); | ||
} | ||
|
||
@Override | ||
public String getExampleInput() { | ||
return "Gimme shel-\nter"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...t/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.jabref.logic.formatter.bibtexfields; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class RemoveHyphenatedNewlinesFormatterTest { | ||
private RemoveHyphenatedNewlinesFormatter formatter; | ||
|
||
@Before | ||
public void setUp() { | ||
formatter = new RemoveHyphenatedNewlinesFormatter(); | ||
} | ||
|
||
@Test | ||
public void removeHyphensBeforeNewlines() { | ||
assertEquals("water", formatter.format("wa-\nter")); | ||
assertEquals("water", formatter.format("wa-\r\nter")); | ||
assertEquals("water", formatter.format("wa-\rter")); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.jabref.logic.formatter.bibtexfields; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class RemoveNewlinesFormatterTest { | ||
private RemoveNewlinesFormatter formatter; | ||
|
||
@Before | ||
public void setUp() { | ||
formatter = new RemoveNewlinesFormatter(); | ||
} | ||
|
||
@Test | ||
public void removeCarriageReturnLineFeed() { | ||
assertEquals("rn linebreak", formatter.format("rn\r\nlinebreak")); | ||
} | ||
|
||
@Test | ||
public void removeCarriageReturn() { | ||
assertEquals("r linebreak", formatter.format("r\rlinebreak")); | ||
} | ||
|
||
@Test | ||
public void removeLineFeed() { | ||
assertEquals("n linebreak", formatter.format("n\nlinebreak")); | ||
} | ||
} |