Java String Capitalize Full capitalizeFully(String str)

Here you can find the source of capitalizeFully(String str)

Description

capitalize Fully

License

Mozilla Public License

Declaration

public static String capitalizeFully(String str) 

Method Source Code

//package com.java2s;
//License from project: Mozilla Public License 

public class Main {
    public static String capitalizeFully(String str) {
        return capitalizeFully(str, null);
    }//from   w ww  . j a  va  2  s . c  o  m

    public static String capitalizeFully(String str, char[] delimiters) {
        int delimLen = (delimiters == null ? -1 : delimiters.length);

        if (str == null || str.length() == 0 || delimLen == 0) {
            return str;
        }

        str = str.toLowerCase();

        return capitalize(str, delimiters);
    }

    public static String capitalize(String str) {
        return capitalize(str, null);
    }

    public static String capitalize(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. capitalizeFully(String input)
  2. capitalizeFully(String input, String delimiters)
  3. capitalizeFully(String str)
  4. capitalizeFully(String str)
  5. capitalizeFully(String str)
  6. capitalizeFully(String str, final char... delimiters)
  7. capitalizeFully(String str, final char... delimiters)
  8. capitalizeFully(String string)