我使用JCSV编写了一个简单的解析器来解析csv内容,但它似乎没有在封闭的单引号内维护行尾字符,是否有更多的配置或者JCSV不具备它? / p>
public class CSVUtil {
final static Logger logger = LoggerFactory.getLogger(CSVUtil.class);
public static List<String[]> readCSV(InputStream is) throws IOException {
Reader reader = new InputStreamReader(is);
CSVReader<String[]> csvParser =
new CSVReaderBuilder<String[]>(reader)
.entryParser(new DefaultCSVEntryParser())
.strategy(CSVStrategy.UK_DEFAULT).build();
return csvParser.readAll();
}
public static List<String[]> readCSV(String csvdata) throws IOException {
InputStream is = new ByteArrayInputStream( csvdata.getBytes( "utf-8" ) );
return readCSV(is);
}
}
//我的常规测试
@Test
public void testEndOfLineEnclosedWithSingleQuote() {
def csv = '''
one,'two 2 , 2 ,
2 , 2 2 2',three
one,two,three,four
'''
def results = CSVUtil.readCSV(csv);
println(results)
assert results.size == 2
}
Assertion failed:
assert results.size == 2
| | |
| 3 false
[[one, 'two 2 , 2 , ], [2 , 2 2 2', three], [one, two, three, four]]