diff --git a/src/main/java/cn/octopusyan/dmt/utils/csv/CsvParser.java b/src/main/java/cn/octopusyan/dmt/utils/csv/CsvParser.java index 99ed94a..8792536 100644 --- a/src/main/java/cn/octopusyan/dmt/utils/csv/CsvParser.java +++ b/src/main/java/cn/octopusyan/dmt/utils/csv/CsvParser.java @@ -38,6 +38,10 @@ public final class CsvParser extends ComputeIter implements Closeable, S * 是否在引号包装内 */ private boolean inQuotes; + /** + * 连续双引号计数 + */ + private int continuousCount = 0; /** * 当前读取字段 */ @@ -257,9 +261,15 @@ public final class CsvParser extends ComputeIter implements Closeable, S if (inQuotes) { //引号内,作为内容,直到引号结束 if (c == config.textDelimiter) { - // End of quoted text - inQuotes = false; + if(buf.canRead(1) && buf.read(1) == CharUtil.DOUBLE_QUOTES) { + continuousCount++; + } else if(continuousCount != 0 && (continuousCount + 1) % 2 == 0) { + continuousCount = 0; + } else { + inQuotes = false; + } } else { + if(continuousCount != 0) continuousCount = 0; // 字段内容中新行 if (isLineEnd(c, preChar)) { inQuotesLineCount++; @@ -450,6 +460,14 @@ public final class CsvParser extends ComputeIter implements Closeable, S return this.buf[this.position++]; } + boolean canRead(int position) { + return (this.position + position - 1) < limit; + } + + char read(int position) { + return this.buf[this.position + position - 1]; + } + /** * 标记位置记为下次读取位置 */