Skip to content
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

open office csv format correction for abstract column #9570

Merged
merged 5 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/logic/layout/LayoutEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.jabref.logic.layout.format.RemoveTilde;
import org.jabref.logic.layout.format.RemoveWhitespace;
import org.jabref.logic.layout.format.Replace;
import org.jabref.logic.layout.format.ReplaceWithEscapedDoubleQuotes;
import org.jabref.logic.layout.format.RisAuthors;
import org.jabref.logic.layout.format.RisKeywords;
import org.jabref.logic.layout.format.RisMonth;
Expand Down Expand Up @@ -475,6 +476,7 @@ private LayoutFormatter getLayoutFormatterByName(String name) {
case "Markdown" -> new MarkdownFormatter();
case "CSLType" -> new CSLType();
case "ShortMonth" -> new ShortMonthFormatter();
case "ReplaceWithEscapedDoubleQuotes" -> new ReplaceWithEscapedDoubleQuotes();
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.jabref.logic.layout.format;

import org.jabref.logic.layout.LayoutFormatter;

public class ReplaceWithEscapedDoubleQuotes implements LayoutFormatter {
@Override
public String format(String fieldText) {
StringBuilder builder = new StringBuilder(fieldText.length());

for (char c : fieldText.toCharArray()) {
if (c == '\"') {
builder.append("\"\"");
} else {
builder.append(c);
}
}
return builder.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
\format[GetOpenOfficeType]{\entrytype},"\begin{isbn}\isbn\end{isbn}","\citationkey","\format[Authors(LastFirst,FullName,Semicolon,Semicolon)]{\author}","\format[RemoveBrackets,RemoveWhitespace]{\title}","\journal",\volume,\number,"\month","\pages",\year,"\address","\note","\url","\booktitle","\chapter","\edition","\series","\format[Authors(LastFirst,FullName,Semicolon,Semicolon)]{\editor}","\publisher","\begin{reporttype}\reporttype\end{reporttype}","\howpublished","\institution","\organization","\school","\annote","\format[Replace(\n, )]{\abstract}","\comment","\keywords","\format[FileLink(pdf)]{\file}","\key"
\format[GetOpenOfficeType]{\entrytype},"\begin{isbn}\isbn\end{isbn}","\citationkey","\format[Authors(LastFirst,FullName,Semicolon,Semicolon)]{\author}","\format[RemoveBrackets,RemoveWhitespace]{\title}","\journal",\volume,\number,"\month","\pages",\year,"\address","\note","\url","\booktitle","\chapter","\edition","\series","\format[Authors(LastFirst,FullName,Semicolon,Semicolon)]{\editor}","\publisher","\begin{reporttype}\reporttype\end{reporttype}","\howpublished","\institution","\organization","\school","\annote","\format[Replace(\n, ),ReplaceWithEscapedDoubleQuotes]{\abstract}","\comment","\keywords","\format[FileLink(pdf)]{\file}","\key"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.jabref.logic.formatter.bibtexfields;

import org.jabref.logic.layout.format.ReplaceWithEscapedDoubleQuotes;

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

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

public class ReplaceWithEscapedDoubleQuotesTest {

private ReplaceWithEscapedDoubleQuotes formatter;

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

@Test
public void replacingSingleDoubleQuote() {
assertEquals("single \"\"double quote", formatter.format("single \"double quote"));
}

@Test
public void replacingMultipleDoubleQuote() {
assertEquals("multiple \"\"double\"\" quote", formatter.format("multiple \"double\" quote"));
}

@Test
public void replacingSingleDoubleQuoteHavingCommas() {
assertEquals("this \"\"is\"\", a test", formatter.format("this \"is\", a test"));
}

@Test
public void doNothing() {
assertEquals("this is a test", formatter.format("this is a test"));
}
}