[英]Unexpected quoting in Apache Commons CSV
在使用具有以下maven依赖关系的Apache CSV时。 我得到了意外的结果。
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.2</version>
</dependency>
简单的代码对我不起作用。 谁能告诉我这是怎么回事?
System.out.println(CSVFormat.DEFAULT.format("-10","10"));
实际输出: "-10",10
预期产量: -10,10
System.out.println(CSVFormat.DEFAULT.format("10","-10"));
实际输出: 10,-10
预期产量: 10,-10
System.out.println(CSVFormat.DEFAULT.format(".10","-10"));
实际输出: ".10",-10
预期输出: .10,-10
System.out.println(CSVFormat.DEFAULT.format("+10","-10"));
实际输出: "+10",-10
预期输出: +10,-10
您在上面列出的实际结果是合法的CSV格式(即使带引号也可以解析),但是我可以看到它看起来像是意外的输出。
这是CSVPrinter.java
的源代码 :
// TODO where did this rule come from?
if (newRecord && (c < '0' || (c > '9' && c < 'A') || (c > 'Z' && c < 'a') || (c > 'z'))) {
quote = true;
}
如果该代码不是以字母数字字符开头,则它将引用该行中的第一项。
如果浏览该类的代码历史记录 ,则会发现此行为自存储库开始(2011年11月9日)以来就一直存在。
我没有在问题跟踪器上发现任何相关的错误,因此,如果您认为应该更改默认行为,则应该打开一个问题。 或者,你可以考虑使用一个应用QuoteMode使用CSVFormat.withQuoteMode()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.