EmojiUtil.java
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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));
}
}