You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by st...@apache.org on 2018/02/09 14:21:56 UTC
[31/34] commons-csv git commit: [CSV-220] Add API
org.apache.commons.csv.CSVFormat.withSystemRecordSeparator().
[CSV-220] Add API
org.apache.commons.csv.CSVFormat.withSystemRecordSeparator().
Project: http://git-wip-us.apache.org/repos/asf/commons-csv/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-csv/commit/3a203443
Tree: http://git-wip-us.apache.org/repos/asf/commons-csv/tree/3a203443
Diff: http://git-wip-us.apache.org/repos/asf/commons-csv/diff/3a203443
Branch: refs/heads/CSV-216
Commit: 3a2034434cf29e241378f5f0cdbb9be6cf01eaba
Parents: 34262e8
Author: Gary Gregory <gg...@apache.org>
Authored: Mon Dec 11 11:50:31 2017 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Mon Dec 11 11:50:31 2017 -0700
----------------------------------------------------------------------
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/csv/CSVFormat.java | 16 ++++++++++++++++
.../java/org/apache/commons/csv/CSVFormatTest.java | 8 +++++++-
3 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-csv/blob/3a203443/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 302632e..217c2ce 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -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>
http://git-wip-us.apache.org/repos/asf/commons-csv/blob/3a203443/src/main/java/org/apache/commons/csv/CSVFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java
index 9e6c807..10f766d 100644
--- a/src/main/java/org/apache/commons/csv/CSVFormat.java
+++ b/src/main/java/org/apache/commons/csv/CSVFormat.java
@@ -1926,6 +1926,22 @@ public final class CSVFormat implements Serializable {
}
/**
+ * 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.
*
* @return A new CSVFormat that is equal to this but with the trailing delimiter setting.
http://git-wip-us.apache.org/repos/asf/commons-csv/blob/3a203443/src/test/java/org/apache/commons/csv/CSVFormatTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
index 9a69780..6a96c7c 100644
--- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
@@ -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());
+ }
+
}