Java String Capitalize Full capitalizeFully(String str, final char... delimiters)

Here you can find the source of capitalizeFully(String str, final char... delimiters)

Description

capitalize Fully

License

Open Source License

Declaration

public static String capitalizeFully(String str, final char... delimiters) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String capitalizeFully(String str, final char... delimiters) {
        final int delimLen = delimiters == null ? -1 : delimiters.length;
        if (isEmpty(str) || delimLen == 0) {
            return str;
        }//  w  ww.ja va  2s.c o m
        str = str.toLowerCase();
        return capitalize(str, delimiters);
    }

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

    public static String capitalize(final String str, final char... delimiters) {
        final int delimLen = delimiters == null ? -1 : delimiters.length;
        if (isEmpty(str) || delimLen == 0) {
            return str;
        }
        final char[] buffer = str.toCharArray();
        boolean capitalizeNext = true;
        for (int i = 0; i < buffer.length; i++) {
            final char ch = buffer[i];
            if (isDelimiter(ch, delimiters)) {
                capitalizeNext = true;
            } else if (capitalizeNext) {
                buffer[i] = Character.toTitleCase(ch);
                capitalizeNext = false;
            }
        }
        return new String(buffer);
    }

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

Related

  1. capitalizeFully(String input, String delimiters)
  2. capitalizeFully(String str)
  3. capitalizeFully(String str)
  4. capitalizeFully(String str)
  5. capitalizeFully(String str)
  6. capitalizeFully(String str, final char... delimiters)
  7. capitalizeFully(String string)
  8. capitalizeFully(String text)
  9. capitalizeFully(String to_capitalize)