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
This commit is contained in:
parent
77c0980816
commit
05fdf22a6c
|
@ -35,7 +35,7 @@ public class CSVStrategy implements Cloneable, Serializable {
|
||||||
public static char COMMENTS_DISABLED = (char) 0;
|
public static char COMMENTS_DISABLED = (char) 0;
|
||||||
|
|
||||||
public static CSVStrategy DEFAULT_STRATEGY = new CSVStrategy(',', '"', COMMENTS_DISABLED, true, false, true);
|
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);
|
public static CSVStrategy TDF_STRATEGY = new CSVStrategy(' ', '"', COMMENTS_DISABLED, true, false, true);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -272,8 +272,8 @@ public class CSVParserTest extends TestCase {
|
||||||
|
|
||||||
public void testExcelStrategy1() throws IOException {
|
public void testExcelStrategy1() throws IOException {
|
||||||
String code =
|
String code =
|
||||||
"value1;value2;value3;value4\r\na;b;c;d\r\n x;;;"
|
"value1,value2,value3,value4\r\na,b,c,d\r\n x,,,"
|
||||||
+ "\r\n\r\n\"\"\"hello\"\"\";\" \"\"world\"\"\";\"abc\ndef\";\r\n";
|
+ "\r\n\r\n\"\"\"hello\"\"\",\" \"\"world\"\"\",\"abc\ndef\",\r\n";
|
||||||
String[][] res = {
|
String[][] res = {
|
||||||
{"value1", "value2", "value3", "value4"},
|
{"value1", "value2", "value3", "value4"},
|
||||||
{"a", "b", "c", "d"},
|
{"a", "b", "c", "d"},
|
||||||
|
@ -281,8 +281,7 @@ public class CSVParserTest extends TestCase {
|
||||||
{""},
|
{""},
|
||||||
{"\"hello\"", " \"world\"", "abc\ndef", ""}
|
{"\"hello\"", " \"world\"", "abc\ndef", ""}
|
||||||
};
|
};
|
||||||
CSVParser parser = new CSVParser(new StringReader(code));
|
CSVParser parser = new CSVParser(new StringReader(code), CSVStrategy.EXCEL_STRATEGY);
|
||||||
parser.setStrategy(CSVStrategy.EXCEL_STRATEGY);
|
|
||||||
System.out.println("---------\n" + code + "\n-------------");
|
System.out.println("---------\n" + code + "\n-------------");
|
||||||
String[][] tmp = parser.getAllValues();
|
String[][] tmp = parser.getAllValues();
|
||||||
assertEquals(res.length, tmp.length);
|
assertEquals(res.length, tmp.length);
|
||||||
|
@ -293,7 +292,7 @@ public class CSVParserTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExcelStrategy2() throws Exception {
|
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 = {
|
String[][] res = {
|
||||||
{"foo", "baar"},
|
{"foo", "baar"},
|
||||||
{""},
|
{""},
|
||||||
|
@ -317,14 +316,14 @@ public class CSVParserTest extends TestCase {
|
||||||
|
|
||||||
public void testEndOfFileBehaviourExcel() throws Exception {
|
public void testEndOfFileBehaviourExcel() throws Exception {
|
||||||
String[] codes = {
|
String[] codes = {
|
||||||
"hello;\r\n\r\nworld;\r\n",
|
"hello,\r\n\r\nworld,\r\n",
|
||||||
"hello;\r\n\r\nworld;",
|
"hello,\r\n\r\nworld,",
|
||||||
"hello;\r\n\r\nworld;\"\"\r\n",
|
"hello,\r\n\r\nworld,\"\"\r\n",
|
||||||
"hello;\r\n\r\nworld;\"\"",
|
"hello,\r\n\r\nworld,\"\"",
|
||||||
"hello;\r\n\r\nworld;\n",
|
"hello,\r\n\r\nworld,\n",
|
||||||
"hello;\r\n\r\nworld;",
|
"hello,\r\n\r\nworld,",
|
||||||
"hello;\r\n\r\nworld;\"\"\n",
|
"hello,\r\n\r\nworld,\"\"\n",
|
||||||
"hello;\r\n\r\nworld;\"\""
|
"hello,\r\n\r\nworld,\"\""
|
||||||
};
|
};
|
||||||
String[][] res = {
|
String[][] res = {
|
||||||
{"hello", ""},
|
{"hello", ""},
|
||||||
|
@ -384,10 +383,10 @@ public class CSVParserTest extends TestCase {
|
||||||
|
|
||||||
public void testEmptyLineBehaviourExcel() throws Exception {
|
public void testEmptyLineBehaviourExcel() throws Exception {
|
||||||
String[] codes = {
|
String[] codes = {
|
||||||
"hello;\r\n\r\n\r\n",
|
"hello,\r\n\r\n\r\n",
|
||||||
"hello;\n\n\n",
|
"hello,\n\n\n",
|
||||||
"hello;\"\"\r\n\r\n\r\n",
|
"hello,\"\"\r\n\r\n\r\n",
|
||||||
"hello;\"\"\n\n\n"
|
"hello,\"\"\n\n\n"
|
||||||
};
|
};
|
||||||
String[][] res = {
|
String[][] res = {
|
||||||
{"hello", ""},
|
{"hello", ""},
|
||||||
|
|
|
@ -70,16 +70,16 @@ public class CSVPrinterTest extends TestCase {
|
||||||
printer.setStrategy(CSVStrategy.EXCEL_STRATEGY);
|
printer.setStrategy(CSVStrategy.EXCEL_STRATEGY);
|
||||||
String[] line1 = {"a", "b"};
|
String[] line1 = {"a", "b"};
|
||||||
printer.println(line1);
|
printer.println(line1);
|
||||||
assertEquals("a;b" + lineSeparator, sw.toString());
|
assertEquals("a,b" + lineSeparator, sw.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExcelPrinter2() {
|
public void testExcelPrinter2() {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
CSVPrinter printer = new CSVPrinter(sw);
|
CSVPrinter printer = new CSVPrinter(sw);
|
||||||
printer.setStrategy(CSVStrategy.EXCEL_STRATEGY);
|
printer.setStrategy(CSVStrategy.EXCEL_STRATEGY);
|
||||||
String[] line1 = {"a;b", "b"};
|
String[] line1 = {"a,b", "b"};
|
||||||
printer.println(line1);
|
printer.println(line1);
|
||||||
assertEquals("\"a;b\";b" + lineSeparator, sw.toString());
|
assertEquals("\"a,b\",b" + lineSeparator, sw.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class CSVStrategyTest extends TestCase {
|
||||||
|
|
||||||
public void testSetExcelStrategy() {
|
public void testSetExcelStrategy() {
|
||||||
CSVStrategy strategy = CSVStrategy.EXCEL_STRATEGY;
|
CSVStrategy strategy = CSVStrategy.EXCEL_STRATEGY;
|
||||||
assertEquals(strategy.getDelimiter(), ';');
|
assertEquals(strategy.getDelimiter(), ',');
|
||||||
assertEquals(strategy.getEncapsulator(), '"');
|
assertEquals(strategy.getEncapsulator(), '"');
|
||||||
assertEquals(strategy.getCommentStart(), '\0');
|
assertEquals(strategy.getCommentStart(), '\0');
|
||||||
assertEquals(false, strategy.getIgnoreLeadingWhitespaces());
|
assertEquals(false, strategy.getIgnoreLeadingWhitespaces());
|
||||||
|
|
Loading…
Reference in New Issue