Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id EA730200D57 for ; Mon, 11 Dec 2017 19:50:39 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id E9120160C22; Mon, 11 Dec 2017 18:50:39 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 397C9160C03 for ; Mon, 11 Dec 2017 19:50:39 +0100 (CET) Received: (qmail 12651 invoked by uid 500); 11 Dec 2017 18:50:38 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 12642 invoked by uid 99); 11 Dec 2017 18:50:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Dec 2017 18:50:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2C89FDFAB9; Mon, 11 Dec 2017 18:50:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ggregory@apache.org To: commits@commons.apache.org Date: Mon, 11 Dec 2017 18:50:35 -0000 Message-Id: In-Reply-To: <571c4822c0264cbdadb7a25560c20daa@git.apache.org> References: <571c4822c0264cbdadb7a25560c20daa@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] commons-csv git commit: [CSV-220] Add API org.apache.commons.csv.CSVFormat.withSystemRecordSeparator(). archived-at: Mon, 11 Dec 2017 18:50:40 -0000 [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/master Commit: 3a2034434cf29e241378f5f0cdbb9be6cf01eaba Parents: 34262e8 Author: Gary Gregory Authored: Mon Dec 11 11:50:31 2017 -0700 Committer: Gary Gregory 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 @@ Add autoFlush option for CsvPrinter. PR #24. The behavior of quote char using is not similar as Excel does when the first string contains CJK char(s). Don't quote cells just because they have UTF-8 encoded characters. + Add API org.apache.commons.csv.CSVFormat.withSystemRecordSeparator(). withNullString value is printed without quotes when QuoteMode.ALL is specified; add QuoteMode.ALL_NON_NULL. PR #17. 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. + * + *

+ * Note: This setting is only used during printing and does not affect parsing. Parsing currently + * only works for inputs with '\n', '\r' and "\r\n" + *

+ * + * @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()); + } + }