Add code and test for Quote.NONE

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1480499 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2013-05-08 23:54:22 +00:00
parent bb3bb0d65b
commit 512e446d28
2 changed files with 14 additions and 1 deletions

View File

@ -242,7 +242,9 @@ public class CSVPrinter implements Flushable, Closeable {
quote = !(object instanceof Number);
break;
case NONE:
throw new IllegalArgumentException("Not implemented yet");
// Use the existing escaping code
printAndEscape(value, offset, len);
return;
case MINIMAL:
if (len <= 0) {
// always quote an empty token that is the first

View File

@ -381,6 +381,17 @@ public class CSVPrinterTest {
printer.close();
}
@Test
public void testDelimeterQuoteNONE() throws IOException {
final StringWriter sw = new StringWriter();
final CSVFormat format = CSVFormat.newBuilder().withEscape('!').withQuotePolicy(Quote.NONE).build();
final CSVPrinter printer = new CSVPrinter(sw, format);
printer.print("a,b,c");
printer.print("xyz");
assertEquals("a!,b!,c,xyz", sw.toString());
printer.close();
}
@Test
public void testEOLQuoted() throws IOException {
final StringWriter sw = new StringWriter();