zoukankan      html  css  js  c++  java
  • emoji图像转码解码 存入数据库

    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();
    }

  • 相关阅读:
    HDU3085 Nightmare Ⅱ (双向BFS)
    LuoguP2523 [HAOI2011]Problem c(概率DP)
    BZOJ4569 [Scoi2016]萌萌哒(并查集,倍增)
    CF360E Levko and Game(贪心)
    总结-小技巧
    总结-二分
    总结-莫队
    $P1821 [USACO07FEB]银牛派对Silver Cow Party$
    $P2126 Mzc家中的男家丁$
    $P5017 摆渡车$
  • 原文地址:https://www.cnblogs.com/austinspark-jessylu/p/5984330.html
Copyright © 2011-2022 走看看