-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial attempt at creating a regex modifier for key patterns
- Loading branch information
1 parent
43cd266
commit 04cde60
Showing
3 changed files
with
69 additions
and
1 deletion.
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
49 changes: 49 additions & 0 deletions
49
src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.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,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; | ||
} | ||
|
||
} |
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