|
@ -1,10 +1,9 @@ |
|
|
package com.epmet.commons.tools.utils; |
|
|
package com.epmet.commons.tools.utils; |
|
|
|
|
|
|
|
|
import java.util.regex.Matcher; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* desc: |
|
|
* desc:utf8mb4转为utf8 |
|
|
* |
|
|
* |
|
|
* @author: LiuJanJun |
|
|
* @author: LiuJanJun |
|
|
* @date: 2022/7/22 9:45 下午 |
|
|
* @date: 2022/7/22 9:45 下午 |
|
@ -12,18 +11,27 @@ import java.util.regex.Pattern; |
|
|
*/ |
|
|
*/ |
|
|
public class StrUtil { |
|
|
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) { |
|
|
public static String filterEmoji(String source) { |
|
|
|
|
|
if (StringUtils.isBlank(source)) { |
|
|
if (source != null) { |
|
|
|
|
|
Matcher emojiMatcher = emoji.matcher(source); |
|
|
|
|
|
if (emojiMatcher.find()) { |
|
|
|
|
|
source = emojiMatcher.replaceAll(""); |
|
|
|
|
|
return 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 source; |
|
|
} |
|
|
|
|
|
return sb.toString(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
String x = StrUtil.filterEmoji("😀😁😆😅🥹🥹😇😗😀😂666"); |
|
|
|
|
|
System.out.println(x); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|