From: <zep...@us...> - 2012-01-10 15:54:42
|
Revision: 431 http://flatpack.svn.sourceforge.net/flatpack/?rev=431&view=rev Author: zepernick Date: 2012-01-10 15:54:32 +0000 (Tue, 10 Jan 2012) Log Message: ----------- Fixed a bug where the writer was not qualifying elements that contained a qualifier Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java 2012-01-10 15:43:41 UTC (rev 430) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java 2012-01-10 15:54:32 UTC (rev 431) @@ -56,7 +56,7 @@ } } - final boolean needsQuoting = (stringValue.indexOf(delimiter) != -1); + final boolean needsQuoting = stringValue.indexOf(delimiter) != -1 || (qualifier != FPConstants.NO_QUALIFIER && stringValue.indexOf(qualifier) != -1); if (needsQuoting) { super.write(qualifier); Modified: trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java 2012-01-10 15:43:41 UTC (rev 430) +++ trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java 2012-01-10 15:54:32 UTC (rev 431) @@ -106,15 +106,19 @@ final DelimiterWriterFactory factory = new DelimiterWriterFactory(';', '"'); factory.addColumnTitle("col1"); factory.addColumnTitle("col2"); + factory.addColumnTitle("col3"); + factory.addColumnTitle("col4"); final StringWriter out = new StringWriter(); final Writer writer = factory.createWriter(out); writer.addRecordEntry("col1", "value;with;delimiter"); writer.addRecordEntry("col2", "normal value"); + writer.addRecordEntry("col3", "value \"with qualifier\""); + writer.addRecordEntry("col4", "value \"with qualifier\" and ;delimiter;"); writer.nextRecord(); writer.flush(); - final String expected = this.joinLines("col1;col2", "\"value;with;delimiter\";normal value"); + final String expected = this.joinLines("col1;col2;col3;col4", "\"value;with;delimiter\";normal value;\"value \"with qualifier\"\";\"value \"with qualifier\" and ;delimiter;\""); Assert.assertEquals(expected, out.toString()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |