package com.action.eimoji;

import com.github.binarywang.java.emoji.EmojiConverter;
import com.vdurmont.emoji.EmojiParser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @program: WebUploader
 * @description: Emoji
 * @author: Dai Yuanchuan
 * @create: 2018-07-11 16:55
 **/
@Controller
@RequestMapping(value = "/emoji")
public class EmojiUtil {

    private EmojiConverter emojiConverter = EmojiConverter.getInstance();

    /**
     * 将emojiStr转为 带有表情的字符
     * @param emojiStr
     * @return
     */
    @RequestMapping(value = "/emojiConverterUnicodeStr")
    public String emojiConverterUnicodeStr(String emojiStr){
        String result = emojiConverter.toUnicode(emojiStr);
        return result;
    }



    public String emojiConverterToAlias(String str){
        System.out.println(str);
        String result=emojiConverter.toAlias(str);
        System.out.println("==================================");
        System.out.println(EmojiParser.parseToHtmlDecimal(str));
        return result;
    }

    /**
     * 带有表情的字符串转换为编码
     * @param str
     * @return
     */
    @RequestMapping(value = "/emojiConverterToAlias")
    public static 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) {
                e.printStackTrace();
                throw e;
            }
        }
        matcher.appendTail(sb);
        System.out.println("emojiConvert " + str + " to " + sb.toString()
                + ", len:" + sb.length());
        return sb.toString();
    }


}
最近下载更多
pzhyzs  LV2 2023年5月31日
666666777888  LV6 2022年11月6日
2511952410  LV9 2022年10月12日
bin54321  LV7 2022年4月9日
木易雨山  LV7 2021年11月2日
羞羞小子  LV13 2021年4月10日
1254859490  LV2 2021年3月3日
helloworldsbsb  LV7 2020年12月27日
123456nty  LV37 2020年11月26日
17600446733  LV21 2020年6月24日
最近浏览更多
1358849392  LV21 4月12日
WBelong  LV7 2023年12月25日
潘潘123456  LV2 2023年12月24日
shuangfu  LV24 2023年12月2日
kele200  LV3 2023年10月31日
19137715150  LV1 2023年6月18日
ice_candy  LV1 2023年6月13日
pzhyzs  LV2 2023年5月31日
xuyy14gg 2023年5月22日
暂无贡献等级
azursswx 2023年2月13日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友