-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export no empty lines in RIS format #3661
Conversation
@@ -257,7 +277,11 @@ public void export(final BibDatabaseContext databaseContext, final Path file, | |||
|
|||
// Write the entry | |||
if (layout != null) { | |||
ps.write(layout.doLayout(entry, databaseContext.getDatabase())); | |||
if (deleteBlankLines) { | |||
ps.write(layout.doLayout(entry, databaseContext.getDatabase()).replaceAll("(?m)^\\s", "")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extract the regex to Pattern. Compile. You can then use it with
.matcher(structure).replaceAll(replace)
And I would suggest a small comment explaining the regex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, done! Although I hardly suspect that this could become a performance problem due to frequent compilation. After all, this would be executed once per RIS entry and even a few thousand compilations probably won't make a noticeable difference.
But well, it surely doesn't hurt to compile only once.
* upstream/master: (46 commits) Replace openoffice jars with libreoffice jars (#3662) Export no empty lines in RIS format (#3661) Remove apache commons logging in favor of slf4j + log4j for JAVA 9 (#3653) fix isbn fetcher test as Joshua Bloch has published a new revivsion of Effetive Java convert to junit5 jupiter Extend RIS import with multiple fields (#3642) Fix ICAR fetcher test which resulted in build failure (#3654) New translations JabRef_en.properties (French) (#3650) Add link to MADR and fix typo [WIP] Add "Convert to BibTeX format" cleanup (#3541) Fix typo Fix typo Quickfix to get build running on all platforms (#3638) New translations JabRef_en.properties (French) New translations JabRef_en.properties (Vietnamese) New translations JabRef_en.properties (Chinese Simplified) New translations JabRef_en.properties (Dutch) New translations JabRef_en.properties (French) New translations JabRef_en.properties (German) New translations JabRef_en.properties (Greek) New translations JabRef_en.properties (Indonesian) ...
This fixes the remaining part of #3634
I had a closer look at the export / layout logic and wow, this is arcane! The code is more than 12 years old and almost as bad as the bibtex parser used to be.
This PR is based on two decisions:
We now have one case (RIS export) where empty lines are not desired. So, I implemented a solution that only changes the behavior of the RIS export, but leaves all others untouched. Nonetheless, it is very easy (single constructor parameter) to let other formats use empty line elimination as well.
The empty line elimination is done using a hardly understandable, but fully functional regex.