Skip to content

Commit 512e446

Browse files
committed
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
1 parent bb3bb0d commit 512e446

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/main/java/org/apache/commons/csv/CSVPrinter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ private void printAndQuote(final Object object, final CharSequence value,
242242
quote = !(object instanceof Number);
243243
break;
244244
case NONE:
245-
throw new IllegalArgumentException("Not implemented yet");
245+
// Use the existing escaping code
246+
printAndEscape(value, offset, len);
247+
return;
246248
case MINIMAL:
247249
if (len <= 0) {
248250
// always quote an empty token that is the first

src/test/java/org/apache/commons/csv/CSVPrinterTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,17 @@ public void testDelimeterQuoted() throws IOException {
381381
printer.close();
382382
}
383383

384+
@Test
385+
public void testDelimeterQuoteNONE() throws IOException {
386+
final StringWriter sw = new StringWriter();
387+
final CSVFormat format = CSVFormat.newBuilder().withEscape('!').withQuotePolicy(Quote.NONE).build();
388+
final CSVPrinter printer = new CSVPrinter(sw, format);
389+
printer.print("a,b,c");
390+
printer.print("xyz");
391+
assertEquals("a!,b!,c,xyz", sw.toString());
392+
printer.close();
393+
}
394+
384395
@Test
385396
public void testEOLQuoted() throws IOException {
386397
final StringWriter sw = new StringWriter();

0 commit comments

Comments
 (0)