Skip to content

Commit 05fdf22

Browse files
committed
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
1 parent 77c0980 commit 05fdf22

4 files changed

Lines changed: 21 additions & 22 deletions

File tree

src/java/org/apache/commons/csv/CSVStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class CSVStrategy implements Cloneable, Serializable {
3535
public static char COMMENTS_DISABLED = (char) 0;
3636

3737
public static CSVStrategy DEFAULT_STRATEGY = new CSVStrategy(',', '"', COMMENTS_DISABLED, true, false, true);
38-
public static CSVStrategy EXCEL_STRATEGY = new CSVStrategy(';', '"', COMMENTS_DISABLED, false, false, false);
38+
public static CSVStrategy EXCEL_STRATEGY = new CSVStrategy(',', '"', COMMENTS_DISABLED, false, false, false);
3939
public static CSVStrategy TDF_STRATEGY = new CSVStrategy(' ', '"', COMMENTS_DISABLED, true, false, true);
4040

4141

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,16 @@ public void testGetAllValues() throws IOException {
272272

273273
public void testExcelStrategy1() throws IOException {
274274
String code =
275-
"value1;value2;value3;value4\r\na;b;c;d\r\n x;;;"
276-
+ "\r\n\r\n\"\"\"hello\"\"\";\" \"\"world\"\"\";\"abc\ndef\";\r\n";
275+
"value1,value2,value3,value4\r\na,b,c,d\r\n x,,,"
276+
+ "\r\n\r\n\"\"\"hello\"\"\",\" \"\"world\"\"\",\"abc\ndef\",\r\n";
277277
String[][] res = {
278278
{"value1", "value2", "value3", "value4"},
279279
{"a", "b", "c", "d"},
280280
{" x", "", "", ""},
281281
{""},
282282
{"\"hello\"", " \"world\"", "abc\ndef", ""}
283283
};
284-
CSVParser parser = new CSVParser(new StringReader(code));
285-
parser.setStrategy(CSVStrategy.EXCEL_STRATEGY);
284+
CSVParser parser = new CSVParser(new StringReader(code), CSVStrategy.EXCEL_STRATEGY);
286285
System.out.println("---------\n" + code + "\n-------------");
287286
String[][] tmp = parser.getAllValues();
288287
assertEquals(res.length, tmp.length);
@@ -293,7 +292,7 @@ public void testExcelStrategy1() throws IOException {
293292
}
294293

295294
public void testExcelStrategy2() throws Exception {
296-
String code = "foo;baar\r\n\r\nhello;\r\n\r\nworld;\r\n";
295+
String code = "foo,baar\r\n\r\nhello,\r\n\r\nworld,\r\n";
297296
String[][] res = {
298297
{"foo", "baar"},
299298
{""},
@@ -317,14 +316,14 @@ public void testExcelStrategy2() throws Exception {
317316

318317
public void testEndOfFileBehaviourExcel() throws Exception {
319318
String[] codes = {
320-
"hello;\r\n\r\nworld;\r\n",
321-
"hello;\r\n\r\nworld;",
322-
"hello;\r\n\r\nworld;\"\"\r\n",
323-
"hello;\r\n\r\nworld;\"\"",
324-
"hello;\r\n\r\nworld;\n",
325-
"hello;\r\n\r\nworld;",
326-
"hello;\r\n\r\nworld;\"\"\n",
327-
"hello;\r\n\r\nworld;\"\""
319+
"hello,\r\n\r\nworld,\r\n",
320+
"hello,\r\n\r\nworld,",
321+
"hello,\r\n\r\nworld,\"\"\r\n",
322+
"hello,\r\n\r\nworld,\"\"",
323+
"hello,\r\n\r\nworld,\n",
324+
"hello,\r\n\r\nworld,",
325+
"hello,\r\n\r\nworld,\"\"\n",
326+
"hello,\r\n\r\nworld,\"\""
328327
};
329328
String[][] res = {
330329
{"hello", ""},
@@ -384,10 +383,10 @@ public void testEndOfFileBehaviorCSV() throws Exception {
384383

385384
public void testEmptyLineBehaviourExcel() throws Exception {
386385
String[] codes = {
387-
"hello;\r\n\r\n\r\n",
388-
"hello;\n\n\n",
389-
"hello;\"\"\r\n\r\n\r\n",
390-
"hello;\"\"\n\n\n"
386+
"hello,\r\n\r\n\r\n",
387+
"hello,\n\n\n",
388+
"hello,\"\"\r\n\r\n\r\n",
389+
"hello,\"\"\n\n\n"
391390
};
392391
String[][] res = {
393392
{"hello", ""},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ public void testExcelPrinter1() {
7070
printer.setStrategy(CSVStrategy.EXCEL_STRATEGY);
7171
String[] line1 = {"a", "b"};
7272
printer.println(line1);
73-
assertEquals("a;b" + lineSeparator, sw.toString());
73+
assertEquals("a,b" + lineSeparator, sw.toString());
7474
}
7575

7676
public void testExcelPrinter2() {
7777
StringWriter sw = new StringWriter();
7878
CSVPrinter printer = new CSVPrinter(sw);
7979
printer.setStrategy(CSVStrategy.EXCEL_STRATEGY);
80-
String[] line1 = {"a;b", "b"};
80+
String[] line1 = {"a,b", "b"};
8181
printer.println(line1);
82-
assertEquals("\"a;b\";b" + lineSeparator, sw.toString());
82+
assertEquals("\"a,b\",b" + lineSeparator, sw.toString());
8383
}
8484

8585
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void testSetCSVStrategy() {
107107

108108
public void testSetExcelStrategy() {
109109
CSVStrategy strategy = CSVStrategy.EXCEL_STRATEGY;
110-
assertEquals(strategy.getDelimiter(), ';');
110+
assertEquals(strategy.getDelimiter(), ',');
111111
assertEquals(strategy.getEncapsulator(), '"');
112112
assertEquals(strategy.getCommentStart(), '\0');
113113
assertEquals(false, strategy.getIgnoreLeadingWhitespaces());

0 commit comments

Comments
 (0)