Return-Path: Delivered-To: apmail-commons-issues-archive@locus.apache.org Received: (qmail 8588 invoked from network); 4 Mar 2008 00:13:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Mar 2008 00:13:59 -0000 Received: (qmail 64101 invoked by uid 500); 4 Mar 2008 00:13:55 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 63644 invoked by uid 500); 4 Mar 2008 00:13:54 -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 63585 invoked by uid 99); 4 Mar 2008 00:13:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Mar 2008 16:13:53 -0800 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, 04 Mar 2008 00:13:27 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 8A820234C085 for ; Mon, 3 Mar 2008 16:12:50 -0800 (PST) Message-ID: <249129267.1204589570566.JavaMail.jira@brutus> Date: Mon, 3 Mar 2008 16:12:50 -0800 (PST) From: "Paul Benedict (JIRA)" To: issues@commons.apache.org Subject: [jira] Commented: (LANG-415) Two new static methods in StringUtils: camelCaseToUnderscoreSeparated(String) and underscoreSeparatedToCamelCase(String) In-Reply-To: <2009939484.1204583935421.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/LANG-415?page=3Dcom.atlassian.j= ira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D125747= 97#action_12574797 ]=20 Paul Benedict commented on LANG-415: ------------------------------------ Is it possible to accomplish this using regular expressions? This is defini= tely not something for StringUtils, imo. I am not saying it doesn't belong = in Commons or Commons Lang, but perhaps WordUtils may be better suited.=20 > Two new static methods in StringUtils: camelCaseToUnderscoreSeparated(Str= ing) and underscoreSeparatedToCamelCase(String) > -------------------------------------------------------------------------= ----------------------------------------------- > > Key: LANG-415 > URL: https://issues.apache.org/jira/browse/LANG-415 > Project: Commons Lang > Issue Type: New Feature > Affects Versions: 2.3 > Reporter: Grzegorz B=C5=82aszczyk > Fix For: 2.4 > > Attachments: LANG-415.patch > > Original Estimate: 1h > Remaining Estimate: 1h > > Index: /CommonsLang/src/java/org/apache/commons/lang/StringUtils.java > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- /CommonsLang/src/java/org/apache/commons/lang/StringUtils.java=09(rev= ision 633306) > +++ /CommonsLang/src/java/org/apache/commons/lang/StringUtils.java=09(wor= king copy) > @@ -2782,6 +2782,60 @@ > list.add(new String(c, tokenStart, c.length - tokenStart)); > return (String[]) list.toArray(new String[list.size()]); > } > + /** > + * Changes a camelCase string value to underscore separated > + * @param input > + * @param toLowerCase - if output string should be lower case > + * @return underscore separated string > + */ > + public static String camelCaseToUnderscoreSeparated(String input, > +=09=09=09boolean toLowerCase) { > +=09=09StringBuilder s =3D new StringBuilder(); > +=09=09if (input =3D=3D null) { > +=09=09=09return ""; > +=09=09} > +=09=09int length =3D input.length(); > +=09=09for (int i =3D 0; i < length; i++) { > +=09=09=09char ch =3D input.charAt(i); > +=09=09=09if (Character.isUpperCase(ch) && i > 0) { > +=09=09=09=09s.append("_"); > +=09=09=09} > +=09=09=09if (ch =3D=3D '.') { > +=09=09=09=09s.append("_"); > +=09=09=09} else { > +=09=09=09=09s.append(toLowerCase ? Character.toLowerCase(ch) : Character > +=09=09=09=09=09=09.toUpperCase(ch)); > +=09=09=09} > +=09=09} > +=09=09return s.toString(); > +=09} > +=09 > + /** > + * Changes a underscore separated string value to camelCase > + * @param input > + * @return camelScape string > + */ > +=09public static String underscoreSeparatedToCamelCase(String input) { > +=09=09StringBuilder s =3D new StringBuilder(); > +=09=09if (input =3D=3D null) { > +=09=09=09return ""; > +=09=09} > +=09=09int length =3D input.length(); > +=09=09boolean upperCase =3D false; > +=09=09 > +=09=09for (int i =3D 0; i < length; i++) { > +=09=09=09char ch =3D input.charAt(i); > +=09=09=09if (ch =3D=3D '_') { > +=09=09=09=09upperCase =3D true; > +=09=09=09} else if (upperCase) { > +=09=09=09=09s.append(Character.toUpperCase(ch)); > +=09=09=09=09upperCase =3D false; > +=09=09=09} else { > +=09=09=09=09s.append(ch); > +=09=09=09} > +=09=09} > +=09=09return s.toString(); > +=09} > =20 > // Joining > //------------------------------------------------------------------= ----- --=20 This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.