Java String Capitalize capitalizeD(String str, char[] delimiters)

Here you can find the source of capitalizeD(String str, char[] delimiters)

Description

capitalize D

License

BSD License

Declaration

public static String capitalizeD(String str, char[] delimiters) 

Method Source Code

//package com.java2s;
/**//w ww. j a v  a  2s  .co  m
 * This class is part of JCodec ( www.jcodec.org ) This software is distributed
 * under FreeBSD License
 * 
 * This code is borrowed from Apache Commons String Utils
 * 
 * @author The JCodec project
 */

public class Main {
    public static String capitalizeD(String str, char[] delimiters) {
        int delimLen = (delimiters == null ? -1 : delimiters.length);
        if (str == null || str.length() == 0 || delimLen == 0) {
            return str;
        }
        int strLen = str.length();
        StringBuilder buffer = new StringBuilder(strLen);
        boolean capitalizeNext = true;
        for (int i = 0; i < strLen; i++) {
            char ch = str.charAt(i);

            if (isDelimiter(ch, delimiters)) {
                buffer.append(ch);
                capitalizeNext = true;
            } else if (capitalizeNext) {
                buffer.append(Character.toTitleCase(ch));
                capitalizeNext = false;
            } else {
                buffer.append(ch);
            }
        }
        return buffer.toString();
    }

    private static boolean isDelimiter(char ch, char[] delimiters) {
        if (delimiters == null) {
            return Character.isWhitespace(ch);
        }
        for (int i = 0, isize = delimiters.length; i < isize; i++) {
            if (ch == delimiters[i]) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. capitalizeAt(StringBuilder builder, int index)
  2. capitalizeClass(String className)
  3. capitalized(String s)
  4. capitalized(String s)
  5. capitalized(String str)
  6. capitalizedArray(String[] sstr)
  7. capitalizedCase(CharSequence source, char... delimiters)
  8. capitalizedName(final String property)
  9. capitalizeFirst(CharSequence str)