package top.imwork.assist.generator.utils;

/**
 * 〈功能简述〉<br> 
 * 〈doc工具〉
 *
 * @author Administrator
 * @create 2020/4/27 0027
 * @since 1.0.0
 */
public class WordUtils {

    public static String capitalizeFully(String str, char... delimiters) {
        int delimLen = delimiters == null ? -1 : delimiters.length;
        if (!StringUtils.isEmpty(str) && delimLen != 0) {
            str = str.toLowerCase();
            return capitalize(str, delimiters);
        } else {
            return str;
        }
    }

    public static String capitalize(String str, char... delimiters) {
        int delimLen = delimiters == null ? -1 : delimiters.length;
        if (!StringUtils.isEmpty(str) && delimLen != 0) {
            char[] buffer = str.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] = Character.toTitleCase(ch);
                    capitalizeNext = false;
                }
            }

            return new String(buffer);
        } else {
            return str;
        }
    }

    private static boolean isDelimiter(char ch, char[] delimiters) {
        if (delimiters == null) {
            return Character.isWhitespace(ch);
        } else {
            char[] var2 = delimiters;
            int var3 = delimiters.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                char delimiter = var2[var4];
                if (ch == delimiter) {
                    return true;
                }
            }

            return false;
        }
    }
}