[ 
https://issues.apache.org/jira/browse/LANG-374?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12543071
 ] 

Niall Pemberton commented on LANG-374:
--------------------------------------

Perhaps would be better to rename the new methods (e.g. escapeDelimited or 
escapeDsv).

I'm no performance expert but I wouldn't have thought creating a new char array 
every time would perform better than (up to) four static calls. Also using 
StringUtils's containsNone() is going to always check the whole String for each 
character - whereas contains() will stop on the first character found.

I've just noticed the indexOfAny() method in StringUtils so perhaps the optimum 
would be a combination, something like...

    private static final char[] CSV_ESPCAPE_CHARS = new char[] {'"', 
CharUtils.CR, CharUtils.LF};

    private static boolean containsCsvChars(String str, char delimiter) {
        return (StringUtils.contains(str, delimiter) || 
StringUtils.indexOfAny(str, CSV_ESPCAPE_CHARS) >= 0);
    }


> Add escaping for CSV columns to StringEscapeUtils
> -------------------------------------------------
>
>                 Key: LANG-374
>                 URL: https://issues.apache.org/jira/browse/LANG-374
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.3
>            Reporter: Niall Pemberton
>            Assignee: Niall Pemberton
>            Priority: Minor
>             Fix For: 2.4
>
>         Attachments: Lang-374-escapeCsv-v2.patch, StringEscapeUtils.patch, 
> StringEscapeUtilsTest.patch
>
>
> Add escaping for CSV columns to StringEscapeUtils.
> Further information on CSV columns available here:
>     http://en.wikipedia.org/wiki/Comma-separated_values
>     http://tools.ietf.org/html/rfc4180

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to