Skip to content

Commit

Permalink
pass line separator as parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr committed Jul 22, 2019
1 parent 11ea190 commit 9b44fa0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fetcher.DoiFetcher;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.StandardFileType;
import org.jabref.logic.xmp.EncryptedPdfsNotSupportedException;
import org.jabref.logic.xmp.XmpUtilReader;
Expand Down Expand Up @@ -215,7 +216,7 @@ public ParserResult importDatabase(Path filePath, Charset defaultEncoding) {
return parserResult;
}

Optional<BibEntry> entry = getEntryFromPDFContent(firstPageContents);
Optional<BibEntry> entry = getEntryFromPDFContent(firstPageContents, OS.NEWLINE);
entry.ifPresent(result::add);

} catch (EncryptedPdfsNotSupportedException e) {
Expand All @@ -231,7 +232,7 @@ public ParserResult importDatabase(Path filePath, Charset defaultEncoding) {
}

//make this method package visible so we can test it
Optional<BibEntry> getEntryFromPDFContent(String firstpageContents) {
Optional<BibEntry> getEntryFromPDFContent(String firstpageContents, String lineSeparator) {

// idea: split[] contains the different lines
// blocks are separated by empty lines
Expand All @@ -241,7 +242,7 @@ Optional<BibEntry> getEntryFromPDFContent(String firstpageContents) {
// i points to the current line
// curString (mostly) contains the current block
// the different lines are joined into one and thereby separated by " "
lines = firstpageContents.split(System.lineSeparator());
lines = firstpageContents.split(lineSeparator);

lineIndex = 0; //to prevent array index out of bounds exception on second run we need to reset i to zero

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@ void testParsingEditorWithoutPagesorSeriesInformation() {
entry.setField(FieldName.PUBLISHER, "Springer");
entry.setField(FieldName.TITLE, "Corpus Linguistics – An International Handbook – Lüdeling, Anke, Kytö, Merja (Eds.)");

String firstPageContents = "Corpus Linguistics – An International Handbook – Lüdeling, Anke,\r\n" +
"Kytö, Merja (Eds.)\r\n" +
"\r\n" +
"Anke Lüdeling, Merja Kytö (Eds.)\r\n" +
"\r\n" +
"VOLUME 2\r\n" +
"\r\n" +
"This handbook provides an up-to-date survey of the field of corpus linguistics, a Handbücher zur Sprach- und\r\n" +
"field whose methodology has revolutionized much of the empirical work done in Kommunikationswissenschaft / Handbooks\r\n" +
"\r\n" +
"of Linguistics and Communication Science\r\n" +
"most fields of linguistic study over the past decade. (HSK) 29/2\r\n" +
"\r\n" +
"vii, 578 pages\r\n" +
"Corpus linguistics investigates human language by starting out from large\r\n";

assertEquals(Optional.of(entry), importer.getEntryFromPDFContent(firstPageContents));
String firstPageContents = "Corpus Linguistics – An International Handbook – Lüdeling, Anke,\n" +
"Kytö, Merja (Eds.)\n" +
"\n" +
"Anke Lüdeling, Merja Kytö (Eds.)\n" +
"\n" +
"VOLUME 2\n" +
"\n" +
"This handbook provides an up-to-date survey of the field of corpus linguistics, a Handbücher zur Sprach- und\n" +
"field whose methodology has revolutionized much of the empirical work done in Kommunikationswissenschaft / Handbooks\n" +
"\n" +
"of Linguistics and Communication Science\n" +
"most fields of linguistic study over the past decade. (HSK) 29/2\n" +
"\n" +
"vii, 578 pages\n" +
"Corpus linguistics investigates human language by starting out from large\n";

assertEquals(Optional.of(entry), importer.getEntryFromPDFContent(firstPageContents, "\n"));
}
}

0 comments on commit 9b44fa0

Please sign in to comment.