public String emojiConvert1(String str)
throws UnsupportedEncodingException {
String patternString = "([\x{10000}-\x{10ffff}ud800-udfff])";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(str);
StringBuffer sb = new StringBuffer();
while(matcher.find()) {
try {
matcher.appendReplacement(
sb,
"[["
+ URLEncoder.encode(matcher.group(1),
"UTF-8") + "]]");
} catch(UnsupportedEncodingException e) {
logger.error("emojiConvert error", e);
throw e;
}
}
matcher.appendTail(sb);
logger.debug("emojiConvert " + str + " to " + sb.toString()
+ ", len:" + sb.length());
return sb.toString();
}
public String emojiRecovery2(String str)
throws UnsupportedEncodingException {
String patternString = "\[\[(.*?)\]\]";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(str);
StringBuffer sb = new StringBuffer();
while(matcher.find()) {
try {
matcher.appendReplacement(sb,
URLDecoder.decode(matcher.group(1), "UTF-8"));
} catch(UnsupportedEncodingException e) {
logger.error("emojiRecovery error", e);
throw e;
}
}
matcher.appendTail(sb);
logger.debug("emojiRecovery " + str + " to " + sb.toString());
return sb.toString();
}