[CSV-220] Add API

org.apache.commons.csv.CSVFormat.withSystemRecordSeparator().
This commit is contained in:
Gary Gregory 2017-12-11 11:50:31 -07:00
parent 34262e8c5e
commit 3a2034434c
3 changed files with 24 additions and 1 deletions

View File

@ -42,6 +42,7 @@
<action issue="CSV-217" type="add" dev="ggregory" due-to="Korolyov Alexei">Add autoFlush option for CsvPrinter. PR #24.</action>
<action issue="CSV-219" type="fix" dev="ggregory" due-to="Zhang Hongda">The behavior of quote char using is not similar as Excel does when the first string contains CJK char(s).</action>
<action issue="CSV-172" type="fix" dev="ggregory" due-to="Andrew Pennebaker">Don't quote cells just because they have UTF-8 encoded characters.</action>
<action issue="CSV-220" type="add" dev="ggregory" due-to="Gary Gregory">Add API org.apache.commons.csv.CSVFormat.withSystemRecordSeparator().</action>
</release>
<release version="1.5" date="2017-09-03" description="Feature and bug fix release">
<action issue="CSV-203" type="fix" dev="ggregory" due-to="Richard Wheeldon, Kai Paroth">withNullString value is printed without quotes when QuoteMode.ALL is specified; add QuoteMode.ALL_NON_NULL. PR #17.</action>

View File

@ -1925,6 +1925,22 @@ public final class CSVFormat implements Serializable {
skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter, autoFlush);
}
/**
* Returns a new {@code CSVFormat} with the record separator of the format set to the operating system's line
* separator string, typically CR+LF on Windows and LF on Linux.
*
* <p>
* <strong>Note:</strong> This setting is only used during printing and does not affect parsing. Parsing currently
* only works for inputs with '\n', '\r' and "\r\n"
* </p>
*
* @return A new CSVFormat that is equal to this but with the operating system's line separator stringr
* @since 1.6
*/
public CSVFormat withSystemRecordSeparator() {
return withRecordSeparator(System.getProperty("line.separator"));
}
/**
* Returns a new {@code CSVFormat} to add a trailing delimiter.
*

View File

@ -640,7 +640,7 @@ public class CSVFormatTest {
public void testToString() {
final CSVFormat cSVFormat = CSVFormat.POSTGRESQL_TEXT;
final String string = cSVFormat.INFORMIX_UNLOAD.toString();
final String string = CSVFormat.INFORMIX_UNLOAD.toString();
assertEquals("Delimiter=<|> Escape=<\\> QuoteChar=<\"> RecordSeparator=<\n> EmptyLines:ignored SkipHeaderRecord:false", string);
@ -1090,4 +1090,10 @@ public class CSVFormatTest {
assertEquals(String.valueOf(LF), formatWithRecordSeparator.getRecordSeparator());
}
@Test
public void testWithSystemRecordSeparator() throws Exception {
final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withSystemRecordSeparator();
assertEquals(System.getProperty("line.separator"), formatWithRecordSeparator.getRecordSeparator());
}
}