EmojiUtil.java 1.2 KB
package cn.com.glsx.entmicro.util;/**
 * @author zhouhaibao
 * @date 2021/10/16
 */

import com.glsx.plat.common.utils.StringUtils;

/**
 * @author zhouhaibao
 * @version 1.0
 * @description: emoji工具类
 * @date 2021/10/16 14:13
 */
public class EmojiUtil {

    /**
     * 转换emoji表情特殊字符的方法
     *
     * @param chars
     * @return
     */
    public static String transform(String chars) {
        if (StringUtils.isEmpty(chars)) {
            return chars;
        }
        StringBuilder emojiChars = new StringBuilder();
        int l = chars.length();
        for (int i = 0; i < l; i++) {
            char _s = chars.charAt(i);
            if (isEmojiCharacter(_s)) {
                emojiChars.append(_s);
            }
        }
        return emojiChars.toString();
    }

    public static boolean isEmojiCharacter(char codePoint) {
        return (codePoint == 0x0) ||
                (codePoint == 0x9) ||
                (codePoint == 0xA) ||
                (codePoint == 0xD) ||
                ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) ||
                ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) ||
                ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF));
    }
}