commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arunvinudss <...@git.apache.org>
Subject [GitHub] commons-text pull request #46: TEXT-85:Added CaseUtils class with camel case...
Date Mon, 12 Jun 2017 14:47:16 GMT
Github user arunvinudss commented on a diff in the pull request:

    https://github.com/apache/commons-text/pull/46#discussion_r121417851
  
    --- Diff: src/main/java/org/apache/commons/text/CaseUtils.java ---
    @@ -0,0 +1,140 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.commons.text;
    +
    +import org.apache.commons.lang3.StringUtils;
    +
    +import java.util.HashSet;
    +import java.util.Set;
    +
    +/**
    + * <p>Case manipulation operations on Strings that contain words.</p>
    + *
    + * <p>This class tries to handle <code>null</code> input gracefully.
    + * An exception will not be thrown for a <code>null</code> input.
    + * Each method documents its behaviour in more detail.</p>
    + *
    + * @since 1.0
    + */
    +public class CaseUtils {
    +
    +    /**
    +     * <p><code>CaseUtils</code> instances should NOT be constructed
in
    +     * standard programming. Instead, the class should be used as
    +     * <code>CaseUtils.toCamelCase("foo bar", true, new char[]{'-'});</code>.</p>
    +     * <p>
    +     * <p>This constructor is public to permit tools that require a JavaBean
    +     * instance to operate.</p>
    +     */
    +    public CaseUtils() {
    +        super();
    +    }
    +
    +    // Camel Case
    +    //-----------------------------------------------------------------------
    +    /**
    +     * <p>Converts all the delimiter separated words in a String into camelCase,
    +     * that is each word is made up of a titlecase character and then a series of
    +     * lowercase characters. The  </p>
    +     *
    +     * <p>The delimiters represent a set of characters understood to separate words.
    +     * The first non-delimiter character after a delimiter will be capitalized. The first
String
    +     * character may or may not be capitalized and it's determined by the user input
for capitalizeFirstLetter
    +     * variable.</p>
    +     *
    +     * <p>A <code>null</code> input String returns <code>null</code>.
    +     * Capitalization uses the Unicode title case, normally equivalent to
    +     * upper case.</p>
    +     *
    +     * <pre>
    +     * CaseUtils.toCamelCase(null, false)                                 = null
    +     * CaseUtils.toCamelCase("", false, *)                                = ""
    +     * CaseUtils.toCamelCase(*, false, null)                              = *
    +     * CaseUtils.toCamelCase(*, true, new char[0])                        = *
    +     * CaseUtils.toCamelCase("To.Camel.Case", false, new char[]{'.'})     = "toCamelCase"
    +     * CaseUtils.toCamelCase(" to @ Camel case", true, new char[]{'@'})   = "toCamelCase"
    +     * CaseUtils.toCamelCase(" @to @ Camel case", false, new char[]{'@'}) = "toCamelCase"
    +     * </pre>
    +     *
    +     * @param str  the String to be converted to camelCase, may be null
    +     * @param capitalizeFirstLetter boolean that determines if the first character of
first word should be title case.
    +     * @param delimiters  set of characters to determine capitalization, null and/or
empty array means whitespace
    +     * @return camelCase of String, <code>null</code> if null String input
    +     */
    +    public static String toCamelCase(String str, boolean capitalizeFirstLetter, final
char... delimiters) {
    --- End diff --
    
    I am a bit biased towards using String instead of CharSequence . Yes CharSequence allows
us to pass String Buffers and builders and other types as input potentially increasing the
scope of the function but considering the nature of work we do in this particular method it
may not necessarily be a good idea. My basic contention is that the minute we call toString()
on a charSequence  to do any sort of manipulation it becomes a costly operation and we may
lose performance . 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message