diff --git a/README.md b/README.md index d81e0ba..ebc4ff9 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ GroovyCSV is available through Maven Central. ## Dependencies * [Groovy 1.8.x](http://groovy.codehaus.org) or later -* [OpenCSV 4.x](http://opencsv.sourceforge.net/) +* [OpenCSV 5.x](http://opencsv.sourceforge.net/) Many thanks to everyone who's contributed to the project and everyone in the OpenCSV team for diff --git a/build.gradle b/build.gradle index 19f51f6..634de6d 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ repositories { } dependencies { - compile 'com.opencsv:opencsv:4.0' + compile 'com.opencsv:opencsv:5.0' compileOnly 'org.codehaus.groovy:groovy-all:1.8.8' testCompile 'org.spockframework:spock-core:1.1-groovy-2.4-rc-2' testCompile 'cglib:cglib-nodep:2.2' diff --git a/src/com/xlson/groovycsv/CsvParser.groovy b/src/com/xlson/groovycsv/CsvParser.groovy index 8c2faa6..c4343a7 100644 --- a/src/com/xlson/groovycsv/CsvParser.groovy +++ b/src/com/xlson/groovycsv/CsvParser.groovy @@ -16,7 +16,11 @@ package com.xlson.groovycsv +import com.opencsv.CSVParser import com.opencsv.CSVReader +import com.opencsv.ICSVParser +import com.opencsv.validators.LineValidatorAggregator +import com.opencsv.validators.RowValidatorAggregator /** * Helper class used to parse information from csv files using the column names @@ -152,11 +156,23 @@ class CsvParser { quoteChar = args.quoteChar ?: '"' } - if (escapeChar != null) { - return new CSVReader(reader, separator, quoteChar, escapeChar, skipLines) - } else { - return new CSVReader(reader, separator, quoteChar, skipLines) + if (escapeChar == null) { + escapeChar = ICSVParser.DEFAULT_ESCAPE_CHARACTER } + CSVParser parser = new CSVParser(separator, quoteChar, escapeChar, + ICSVParser.DEFAULT_STRICT_QUOTES, + ICSVParser.DEFAULT_IGNORE_LEADING_WHITESPACE, + ICSVParser.DEFAULT_IGNORE_QUOTATIONS, + ICSVParser.DEFAULT_NULL_FIELD_INDICATOR, + Locale.getDefault()) + return new CSVReader(reader, skipLines, parser, + CSVReader.DEFAULT_KEEP_CR, + CSVReader.DEFAULT_VERIFY_READER, + CSVReader.DEFAULT_MULTILINE_LIMIT, + Locale.getDefault(), + new LineValidatorAggregator(), + new RowValidatorAggregator(), + null) } /**