From 05fdf22a6c0e142a985ebe0e2a295e9a46a43041 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Fri, 22 Dec 2006 03:42:06 +0000 Subject: [PATCH] change excel strategy to use ',' as the separator: SANDBOX-182 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/sandbox/csv/trunk@489553 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/csv/CSVStrategy.java | 2 +- .../org/apache/commons/csv/CSVParserTest.java | 33 +++++++++---------- .../apache/commons/csv/CSVPrinterTest.java | 6 ++-- .../apache/commons/csv/CSVStrategyTest.java | 2 +- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/java/org/apache/commons/csv/CSVStrategy.java b/src/java/org/apache/commons/csv/CSVStrategy.java index 8bee66f7..af627d1c 100644 --- a/src/java/org/apache/commons/csv/CSVStrategy.java +++ b/src/java/org/apache/commons/csv/CSVStrategy.java @@ -35,7 +35,7 @@ public class CSVStrategy implements Cloneable, Serializable { public static char COMMENTS_DISABLED = (char) 0; public static CSVStrategy DEFAULT_STRATEGY = new CSVStrategy(',', '"', COMMENTS_DISABLED, true, false, true); - public static CSVStrategy EXCEL_STRATEGY = new CSVStrategy(';', '"', COMMENTS_DISABLED, false, false, false); + public static CSVStrategy EXCEL_STRATEGY = new CSVStrategy(',', '"', COMMENTS_DISABLED, false, false, false); public static CSVStrategy TDF_STRATEGY = new CSVStrategy(' ', '"', COMMENTS_DISABLED, true, false, true); diff --git a/src/test/org/apache/commons/csv/CSVParserTest.java b/src/test/org/apache/commons/csv/CSVParserTest.java index 9ad5ad08..53b341ef 100644 --- a/src/test/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/org/apache/commons/csv/CSVParserTest.java @@ -272,8 +272,8 @@ public class CSVParserTest extends TestCase { public void testExcelStrategy1() throws IOException { String code = - "value1;value2;value3;value4\r\na;b;c;d\r\n x;;;" - + "\r\n\r\n\"\"\"hello\"\"\";\" \"\"world\"\"\";\"abc\ndef\";\r\n"; + "value1,value2,value3,value4\r\na,b,c,d\r\n x,,," + + "\r\n\r\n\"\"\"hello\"\"\",\" \"\"world\"\"\",\"abc\ndef\",\r\n"; String[][] res = { {"value1", "value2", "value3", "value4"}, {"a", "b", "c", "d"}, @@ -281,8 +281,7 @@ public class CSVParserTest extends TestCase { {""}, {"\"hello\"", " \"world\"", "abc\ndef", ""} }; - CSVParser parser = new CSVParser(new StringReader(code)); - parser.setStrategy(CSVStrategy.EXCEL_STRATEGY); + CSVParser parser = new CSVParser(new StringReader(code), CSVStrategy.EXCEL_STRATEGY); System.out.println("---------\n" + code + "\n-------------"); String[][] tmp = parser.getAllValues(); assertEquals(res.length, tmp.length); @@ -293,7 +292,7 @@ public class CSVParserTest extends TestCase { } public void testExcelStrategy2() throws Exception { - String code = "foo;baar\r\n\r\nhello;\r\n\r\nworld;\r\n"; + String code = "foo,baar\r\n\r\nhello,\r\n\r\nworld,\r\n"; String[][] res = { {"foo", "baar"}, {""}, @@ -317,14 +316,14 @@ public class CSVParserTest extends TestCase { public void testEndOfFileBehaviourExcel() throws Exception { String[] codes = { - "hello;\r\n\r\nworld;\r\n", - "hello;\r\n\r\nworld;", - "hello;\r\n\r\nworld;\"\"\r\n", - "hello;\r\n\r\nworld;\"\"", - "hello;\r\n\r\nworld;\n", - "hello;\r\n\r\nworld;", - "hello;\r\n\r\nworld;\"\"\n", - "hello;\r\n\r\nworld;\"\"" + "hello,\r\n\r\nworld,\r\n", + "hello,\r\n\r\nworld,", + "hello,\r\n\r\nworld,\"\"\r\n", + "hello,\r\n\r\nworld,\"\"", + "hello,\r\n\r\nworld,\n", + "hello,\r\n\r\nworld,", + "hello,\r\n\r\nworld,\"\"\n", + "hello,\r\n\r\nworld,\"\"" }; String[][] res = { {"hello", ""}, @@ -384,10 +383,10 @@ public class CSVParserTest extends TestCase { public void testEmptyLineBehaviourExcel() throws Exception { String[] codes = { - "hello;\r\n\r\n\r\n", - "hello;\n\n\n", - "hello;\"\"\r\n\r\n\r\n", - "hello;\"\"\n\n\n" + "hello,\r\n\r\n\r\n", + "hello,\n\n\n", + "hello,\"\"\r\n\r\n\r\n", + "hello,\"\"\n\n\n" }; String[][] res = { {"hello", ""}, diff --git a/src/test/org/apache/commons/csv/CSVPrinterTest.java b/src/test/org/apache/commons/csv/CSVPrinterTest.java index d248bbd7..422a79fb 100644 --- a/src/test/org/apache/commons/csv/CSVPrinterTest.java +++ b/src/test/org/apache/commons/csv/CSVPrinterTest.java @@ -70,16 +70,16 @@ public class CSVPrinterTest extends TestCase { printer.setStrategy(CSVStrategy.EXCEL_STRATEGY); String[] line1 = {"a", "b"}; printer.println(line1); - assertEquals("a;b" + lineSeparator, sw.toString()); + assertEquals("a,b" + lineSeparator, sw.toString()); } public void testExcelPrinter2() { StringWriter sw = new StringWriter(); CSVPrinter printer = new CSVPrinter(sw); printer.setStrategy(CSVStrategy.EXCEL_STRATEGY); - String[] line1 = {"a;b", "b"}; + String[] line1 = {"a,b", "b"}; printer.println(line1); - assertEquals("\"a;b\";b" + lineSeparator, sw.toString()); + assertEquals("\"a,b\",b" + lineSeparator, sw.toString()); } } diff --git a/src/test/org/apache/commons/csv/CSVStrategyTest.java b/src/test/org/apache/commons/csv/CSVStrategyTest.java index e4c311cf..ed819463 100644 --- a/src/test/org/apache/commons/csv/CSVStrategyTest.java +++ b/src/test/org/apache/commons/csv/CSVStrategyTest.java @@ -107,7 +107,7 @@ public class CSVStrategyTest extends TestCase { public void testSetExcelStrategy() { CSVStrategy strategy = CSVStrategy.EXCEL_STRATEGY; - assertEquals(strategy.getDelimiter(), ';'); + assertEquals(strategy.getDelimiter(), ','); assertEquals(strategy.getEncapsulator(), '"'); assertEquals(strategy.getCommentStart(), '\0'); assertEquals(false, strategy.getIgnoreLeadingWhitespaces());