提交 eded0362 authored 作者: Thomas Mueller's avatar Thomas Mueller

The new CSV option feature introduced in version 1.3.150 didn't support spaces.…

The new CSV option feature introduced in version 1.3.150 didn't support spaces. Now the escape mechanism is changed to support it.
上级 6adccf4a
......@@ -788,12 +788,15 @@ public class Csv implements SimpleRowSource {
*/
public String setOptions(String options) {
String charset = null;
options = StringUtils.javaDecode(options);
// options = StringUtils.javaDecode(options);
String[] keyValuePairs = StringUtils.arraySplit(options, ' ', false);
for (String pair : keyValuePairs) {
if (pair.length() == 0) {
continue;
}
int index = pair.indexOf('=');
String key = StringUtils.trim(pair.substring(0, index), true, true, " ");
String value = StringUtils.trim(pair.substring(index + 1), true, true, " ");
String value = pair.substring(index + 1);
char ch = value.length() == 0 ? 0 : value.charAt(0);
if (isParam(key, "escape", "esc", "escapeCharacter")) {
setEscapeCharacter(ch);
......
......@@ -80,7 +80,18 @@ public class TestCsv extends TestBase {
assertEquals(",", csv.getFieldSeparatorWrite());
assertEquals(Constants.VERSION_MINOR == 3 ? 0 : '#', csv.getLineCommentCharacter());
String charset = csv.setOptions("escape=1x fieldDelimiter=2x fieldSeparator=3x " +
String charset;
charset = csv.setOptions("escape=\\ fieldDelimiter=\\\\ fieldSeparator=\n " +
"lineComment=\" lineSeparator=\\ \\\\\\ ");
assertEquals(' ', csv.getEscapeCharacter());
assertEquals('\\', csv.getFieldDelimiter());
assertEquals('\n', csv.getFieldSeparatorRead());
assertEquals("\n", csv.getFieldSeparatorWrite());
assertEquals('"', csv.getLineCommentCharacter());
assertEquals(" \\ ", csv.getLineSeparator());
charset = csv.setOptions("escape=1x fieldDelimiter=2x fieldSeparator=3x " +
"lineComment=4x lineSeparator=5x " +
"null=6x rowSeparator=7x charset=8x");
assertEquals('1', csv.getEscapeCharacter());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论