Browse Source

zhuanzhuanzhuan

master
jianjun 3 years ago
parent
commit
6fc8b0b383
  1. 32
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/StrUtil.java

32
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/StrUtil.java

@ -1,10 +1,9 @@
package com.epmet.commons.tools.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
/**
* desc:
* desc:utf8mb4转为utf8
*
* @author: LiuJanJun
* @date: 2022/7/22 9:45 下午
@ -12,18 +11,27 @@ import java.util.regex.Pattern;
*/
public class StrUtil {
private static final Pattern emoji = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]", Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
private static final int LAST_BMP = 0xFFFF;
public static String filterEmoji(String source) {
if (source != null) {
Matcher emojiMatcher = emoji.matcher(source);
if (emojiMatcher.find()) {
source = emojiMatcher.replaceAll("");
return source;
}
if (StringUtils.isBlank(source)) {
return source;
}
return source;
StringBuilder sb = new StringBuilder(source.length());
for (int i = 0; i < source.length(); i++) {
int codePoint = source.codePointAt(i);
if (codePoint < LAST_BMP) {
sb.appendCodePoint(codePoint);
} else {
i++;
}
}
return sb.toString();
}
public static void main(String[] args) {
String x = StrUtil.filterEmoji("😀😁😆😅🥹🥹😇😗😀😂666");
System.out.println(x);
}
}

Loading…
Cancel
Save