Java String Capitalize capitalizedCase(CharSequence source, char... delimiters)

Here you can find the source of capitalizedCase(CharSequence source, char... delimiters)

Description

capitalized Case

License

Open Source License

Declaration

public static String capitalizedCase(CharSequence source, char... delimiters) 

Method Source Code

//package com.java2s;

import static java.lang.Character.*;

public class Main {
    public static String capitalizedCase(CharSequence source) {
        return capitalizedCase(source, null);
    }/*www  .ja  v  a  2  s . c  o m*/

    public static String capitalizedCase(CharSequence source, char... delimiters) {
        int delimitersCount = delimiters == null ? -1 : delimiters.length;
        if (isEmpty(source) || delimitersCount == 0) {
            return source.toString();
        }
        char[] buffer = source.toString().toLowerCase().toCharArray();
        boolean capitalizeNext = true;
        for (int i = 0; i < buffer.length; i++) {
            char ch = buffer[i];
            if (isDelimiter(ch, delimiters)) {
                capitalizeNext = true;
            } else if (capitalizeNext) {
                buffer[i] = toTitleCase(ch);
                capitalizeNext = false;
            }
        }
        return new String(buffer);
    }

    public static boolean isEmpty(CharSequence source) {
        return source == null || source.length() == 0;
    }

    public static boolean isDelimiter(char ch, char[] delimiters) {
        if (delimiters == null) {
            return Character.isWhitespace(ch);
        }
        for (char delimiter : delimiters) {
            if (ch == delimiter) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. capitalized(String s)
  2. capitalized(String s)
  3. capitalized(String str)
  4. capitalizeD(String str, char[] delimiters)
  5. capitalizedArray(String[] sstr)
  6. capitalizedName(final String property)
  7. capitalizeFirst(CharSequence str)
  8. capitalizeFormat(String string)
  9. capitalizeFront(String str)