Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EDF0DD7B4 for ; Fri, 12 Oct 2012 13:56:54 +0000 (UTC) Received: (qmail 13526 invoked by uid 500); 12 Oct 2012 13:56:54 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 13425 invoked by uid 500); 12 Oct 2012 13:56:54 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 13417 invoked by uid 99); 12 Oct 2012 13:56:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Oct 2012 13:56:54 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS,URIBL_DBL_REDIR X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of sebbaz@gmail.com designates 209.85.220.171 as permitted sender) Received: from [209.85.220.171] (HELO mail-vc0-f171.google.com) (209.85.220.171) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Oct 2012 13:56:49 +0000 Received: by mail-vc0-f171.google.com with SMTP id m18so4450156vcm.30 for ; Fri, 12 Oct 2012 06:56:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=OKJy1egv/kWgny1EQsLenk0GOoT/QTMuCpTIna9yIKg=; b=K7iXRj6PBeHpe6irGVGUC/v+pruXf8/0pxGVD3de1uZvXG2VH2tbnYjXMDI1gWG+cE DpLudbPkAMHPsaVJWcGMQZSu50DLXJHXP+X0uUrN9olSNMnG17Kz/31xHap1Q9eCyrOQ F5L9zn9RI2MJdVC8iWxevq2MoLtAjVcLf5mQAwvFOJYLgl8rZWd0A+ZQ7m4eLDw1QS6E Pobt07k/nNwBM9KPPYpjSH0Cv4z7kb1ZhVhTNfBVZYI/Ulqf3oyqaCNzGbM598FqdW/C mfbs3adsvvA4ZZLnAN8RZWLcX0FVvM2JB89e34gE5EPwLnQcUVutIqToJ19pkplxJALX z2fQ== MIME-Version: 1.0 Received: by 10.52.90.147 with SMTP id bw19mr2166699vdb.17.1350050189244; Fri, 12 Oct 2012 06:56:29 -0700 (PDT) Received: by 10.58.172.71 with HTTP; Fri, 12 Oct 2012 06:56:29 -0700 (PDT) In-Reply-To: References: <20121012121244.AC36C23888CD@eris.apache.org> Date: Fri, 12 Oct 2012 14:56:29 +0100 Message-ID: Subject: Re: svn commit: r1397534 - /commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java From: sebb To: Commons Developers List Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org On 12 October 2012 14:50, Gary Gregory wrote: > On Fri, Oct 12, 2012 at 9:39 AM, sebb wrote: > >> On 12 October 2012 13:38, Gary Gregory wrote: >> > On Fri, Oct 12, 2012 at 8:22 AM, Benedikt Ritter > >wrote: >> > >> >> Hi >> >> >> >> 2012/10/12 : >> >> > Author: ggregory >> >> > Date: Fri Oct 12 12:12:44 2012 >> >> > New Revision: 1397534 >> >> > >> >> > URL: http://svn.apache.org/viewvc?rev=1397534&view=rev >> >> > Log: >> >> > Refactor magic strings into constants. >> >> > >> >> > Modified: >> >> > >> >> >> commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java >> >> > >> >> > Modified: >> >> >> commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java >> >> > URL: >> >> >> http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java?rev=1397534&r1=1397533&r2=1397534&view=diff >> >> > >> >> >> ============================================================================== >> >> > --- >> >> >> commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java >> >> (original) >> >> > +++ >> >> >> commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java >> >> Fri Oct 12 12:12:44 2012 >> >> > @@ -25,6 +25,12 @@ import java.io.IOException; >> >> > */ >> >> > public class CSVPrinter { >> >> > >> >> > + private static final char COMMENT = '#'; >> >> >> >> How about COMMENT_START ? >> >> >> > >> > I would say yes only /if/ there were a COMMENT_END. >> >> INLINE_COMMENT_INTRODUCER ? >> > > IS_IT_APRIL_1? No. But I agree it's not an ideal name. It's just that COMMENT on its own is not ideal either. Maybe the solution is to add Javadoc to explain how the # is used to introduce comments. > I do not know you well enough to read you ;) > > G > > >> > Gary >> > >> > >> >> Benedikt >> >> >> >> > + private static final String EMPTY = ""; >> >> > + private static final char SP = ' '; >> >> > + private static final char CR = '\r'; >> >> > + private static final char LF = '\n'; >> >> > + >> >> > /** The place that the values get written. */ >> >> > private final Appendable out; >> >> > private final CSVFormat format; >> >> > @@ -106,19 +112,19 @@ public class CSVPrinter { >> >> > println(); >> >> > } >> >> > out.append(format.getCommentStart()); >> >> > - out.append(' '); >> >> > + out.append(SP); >> >> > for (int i = 0; i < comment.length(); i++) { >> >> > final char c = comment.charAt(i); >> >> > switch (c) { >> >> > - case '\r': >> >> > - if (i + 1 < comment.length() && comment.charAt(i + 1) >> >> == '\n') { >> >> > + case CR: >> >> > + if (i + 1 < comment.length() && comment.charAt(i + 1) >> >> == LF) { >> >> > i++; >> >> > } >> >> > //$FALL-THROUGH$ break intentionally excluded. >> >> > - case '\n': >> >> > + case LF: >> >> > println(); >> >> > out.append(format.getCommentStart()); >> >> > - out.append(' '); >> >> > + out.append(SP); >> >> > break; >> >> > default: >> >> > out.append(c); >> >> > @@ -159,14 +165,14 @@ public class CSVPrinter { >> >> > >> >> > while (pos < end) { >> >> > char c = value.charAt(pos); >> >> > - if (c == '\r' || c == '\n' || c == delim || c == escape) >> { >> >> > + if (c == CR || c == LF || c == delim || c == escape) { >> >> > // write out segment up until this char >> >> > if (pos > start) { >> >> > out.append(value, start, pos); >> >> > } >> >> > - if (c == '\n') { >> >> > + if (c == LF) { >> >> > c = 'n'; >> >> > - } else if (c == '\r') { >> >> > + } else if (c == CR) { >> >> > c = 'r'; >> >> > } >> >> > >> >> > @@ -212,7 +218,7 @@ public class CSVPrinter { >> >> > if (first && (c < '0' || (c > '9' && c < 'A') || (c > 'Z' >> >> && c < 'a') || (c > 'z'))) { >> >> > quote = true; >> >> > // } else if (c == ' ' || c == '\f' || c == '\t') { >> >> > - } else if (c <= '#') { >> >> > + } else if (c <= COMMENT) { >> >> > // Some other chars at the start of a value caused >> the >> >> parser to fail, so for now >> >> > // encapsulate if we start in anything less than '#'. >> >> We are being conservative >> >> > // by including the default comment char too. >> >> > @@ -220,7 +226,7 @@ public class CSVPrinter { >> >> > } else { >> >> > while (pos < end) { >> >> > c = value.charAt(pos); >> >> > - if (c == '\n' || c == '\r' || c == encapsulator >> || >> >> c == delim) { >> >> > + if (c == LF || c == CR || c == encapsulator || c >> == >> >> delim) { >> >> > quote = true; >> >> > break; >> >> > } >> >> > @@ -233,7 +239,7 @@ public class CSVPrinter { >> >> > // if (c == ' ' || c == '\f' || c == '\t') { >> >> > // Some other chars at the end caused the parser >> to >> >> fail, so for now >> >> > // encapsulate if we end in anything less than ' >> ' >> >> > - if (c <= ' ') { >> >> > + if (c <= SP) { >> >> > quote = true; >> >> > } >> >> > } >> >> > @@ -280,7 +286,7 @@ public class CSVPrinter { >> >> > public void print(String value, final boolean checkForEscape) >> >> throws IOException { >> >> > if (value == null) { >> >> > // null values are considered empty >> >> > - value = ""; >> >> > + value = EMPTY; >> >> > } >> >> > >> >> > if (!checkForEscape) { >> >> > >> >> > >> >> >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >> >> For additional commands, e-mail: dev-help@commons.apache.org >> >> >> >> >> > >> > >> > -- >> > E-Mail: garydgregory@gmail.com | ggregory@apache.org >> > JUnit in Action, 2nd Ed: http://bit.ly/ECvg0 >> > Spring Batch in Action: http://bit.ly/bqpbCK >> > Blog: http://garygregory.wordpress.com >> > Home: http://garygregory.com/ >> > Tweet! http://twitter.com/GaryGregory >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >> For additional commands, e-mail: dev-help@commons.apache.org >> >> > > > -- > E-Mail: garydgregory@gmail.com | ggregory@apache.org > JUnit in Action, 2nd Ed: http://bit.ly/ECvg0 > Spring Batch in Action: http://bit.ly/bqpbCK > Blog: http://garygregory.wordpress.com > Home: http://garygregory.com/ > Tweet! http://twitter.com/GaryGregory --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org