使用唯一性解析器和反斜杠转义引号进行CSV解析

z9smfwbn  于 2022-12-15  发布在  其他
关注(0)|答案(1)|浏览(137)

我在解析带有反斜杠转义引号\"的CSV时遇到了一些问题。源CSV中的大多数行不包括转义引号,但在有转义引号的地方,我似乎找不到正确解析的适当设置。
CSV示例(每行4列):

1,,No quote escape,test
2,,"One quote escape\"",test
3,,"Two \"quote escapes\",test
4,,"Two \"quote escapes\" 2",test

CSV解析器设置:

CsvFormat:
        Comment character=#
        Field delimiter=,
        Line separator (normalized)=\n
        Line separator sequence=\r\n
        Quote character="
        Quote escape character=\
        Quote escape escape character=null

代码片段:

CsvParserSettings settings = new CsvParserSettings();

settings.setDelimiterDetectionEnabled(true);
settings.setLineSeparatorDetectionEnabled(true);
settings.getFormat().setQuote('"');
settings.getFormat().setQuoteEscape('\\');

CsvParser parser = new CsvParser(settings);

parser.beginParsing(file, StandardCharsets.UTF_8);
...

正确分析行,直到一行中出现两个转义引号。预期分析的行为:

- 1,null,No quote escape,test
- 2,null,One quote escape",test
- 3,null,Two "quote escapes",test
- 4,null,Two "quote escapes" 2,test
pw9qyyiw

pw9qyyiw1#

经过进一步检查,我发现v2.9.1存在issue

相关问题