package cn.superdesk.uniorder.common.chinese;


/**
 * @Description: 注意：以上方法仅在String内容中包含中文时，才返回true。如果有进行url编码是无法判断的。
 * Java判断String是否包含中文
 * @Author: linjinyu
 * @CreateDate: 2022/6/14 5:58 下午
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/6/14 5:58 下午
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public class AnChineseCharacterUtils {

    private AnChineseCharacterUtils() {

    }

    /**
     * String内容中包含中文时，才返回true。如果有进行url编码是无法判断的。
     *
     * @param strName
     * @return
     */
    public static boolean isChinese(String strName) {
        char[] ch = strName.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            char c = ch[i];
            if (isChinese(c)) {
                return true;
            }
        }
        return false;
    }

    /**
     * String内容中包含中文时，才返回true。如果有进行url编码是无法判断的。
     *
     * @param c
     * @return
     */
    public static boolean isChinese(char c) {
        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
        if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
                || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
                || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
                || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
                || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
                || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION) {
            return true;
        }
        return false;
    }

}
