Return-Path: Delivered-To: apmail-commons-issues-archive@locus.apache.org Received: (qmail 95994 invoked from network); 15 Apr 2008 12:50:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Apr 2008 12:50:09 -0000 Received: (qmail 11172 invoked by uid 500); 15 Apr 2008 12:50:09 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 10971 invoked by uid 500); 15 Apr 2008 12:50:08 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 10962 invoked by uid 99); 15 Apr 2008 12:50:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Apr 2008 05:50:08 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Apr 2008 12:49:33 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 10001234C0D5 for ; Tue, 15 Apr 2008 05:47:05 -0700 (PDT) Message-ID: <1100230486.1208263625064.JavaMail.jira@brutus> Date: Tue, 15 Apr 2008 05:47:05 -0700 (PDT) From: "Emmanuel Bourg (JIRA)" To: issues@commons.apache.org Subject: [jira] Created: (LANG-426) String splitting with escaped delimiter MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org String splitting with escaped delimiter --------------------------------------- Key: LANG-426 URL: https://issues.apache.org/jira/browse/LANG-426 Project: Commons Lang Issue Type: New Feature Affects Versions: 2.4 Reporter: Emmanuel Bourg Priority: Minor Fix For: 3.0 In Commons Configuration we use a custom split method that supports the concept of an escaped delimiter, that may be nice if this was available in Commons Lang (as a method in StringUtils, or as a setting in StrTokenizer). Example: {code} a,b\,c,d -> ["a", "b,c", "d"] {code} Here is the code of the method: {code:java} public static List split(String s, char delimiter) { if (s == null) { return new ArrayList(); } List list = new ArrayList(); StringBuilder token = new StringBuilder(); int begin = 0; boolean inEscape = false; while (begin < s.length()) { char c = s.charAt(begin); if (inEscape) { // last character was the escape marker // can current character be escaped? if (c != delimiter && c != LIST_ESC_CHAR) { // no, also add escape character token.append(LIST_ESC_CHAR); } token.append(c); inEscape = false; } else { if (c == delimiter) { // found a list delimiter -> add token and reset buffer list.add(token.toString().trim()); token = new StringBuilder(); } else if (c == LIST_ESC_CHAR) { // eventually escape next character inEscape = true; } else { token.append(c); } } begin++; } // Trailing delimiter? if (inEscape) { token.append(LIST_ESC_CHAR); } // Add last token list.add(token.toString().trim()); return list; } {code} -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.