import java.io.IOException;
import java.io.InputStream;
import java.lang.Character.UnicodeBlock;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
/**
* @ClassName: EmojiUtil
* @Description:unicode5与unicode6转换(emoji表情)
* 对照文件:emoji.properties
* @author xiaoweiwan
* @date Jun 28, 2012
*/
public class EmojiUtil {
private static EmojiUtil _instance;
private static Properties prop;
private static Properties propValue;
private static final int MIN_UNICODEFIVE = Integer.parseInt("E001",16);
private static final int MAX_UNICODEFIVE = Integer.parseInt("E536",16);
private static final int MIN_UNICODESIX = Integer.parseInt("1F004",16);
private static final int MAX_UNICODESIX = Integer.parseInt("1F6C0",16);
static{
InputStream stream = EmojiUtil.class.getClassLoader().getResourceAsStream("emoji.properties");
prop = new Properties();
propValue = new Properties();
try {
prop.load(stream);
for (Iterator iter = prop.entrySet().iterator(); iter.hasNext();) {
Map.Entry<String,String> entry = (Map.Entry) iter.next();
String unicode5 = (String)entry.getKey();
String unicode6 = (String)entry.getValue();
propValue.put(unicode6, unicode5);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static EmojiUtil getInstance(){
if(_instance == null){
synchronized (EmojiUtil.class) {
_instance = new EmojiUtil();
}
}
return _instance;
}
/**
* @Title: changeUnicodeFiveToSix
* @Description: 使字符串编码如果是Unicode5的emoji字符则转为Unicode6输出
* @param name
* @return
*/
public String changeUnicodeFiveToSix(String name) {
String realname = name;
try{
char[] charArr = name.toCharArray();
StringBuffer sb = new StringBuffer();
int i = 0;
while(i<charArr.length){
char ch = charArr[i];
int unicodeIntVale = 0;
if(Character.isHighSurrogate(ch)){
unicodeIntVale = Character.toCodePoint(ch, charArr[i+1]);
}else{
unicodeIntVale = (int)ch;
}
if( (unicodeIntVale>=MIN_UNICODEFIVE) && (unicodeIntVale<=MAX_UNICODEFIVE) ){
String hexBase = Integer.toHexString(unicodeIntVale).toUpperCase();
String trans = prop.getProperty("\\u"+hexBase);
if(trans!=null){
int second = trans.indexOf("\\u", 2);
if(second<0){
second = trans.indexOf("0x", 2);
}
if(second>0){
sb.append(Character.toChars(Integer.parseInt(trans.substring(0,second).replaceFirst("\\\\u", "").replaceFirst("0x", ""),16)));
sb.append(Character.toChars(Integer.parseInt(trans.substring(second).replaceFirst("\\\\u", "").replaceFirst("0x", ""),16)));
}else{
sb.append(Character.toChars(Integer.parseInt(trans.replaceFirst("\\\\u", "").replaceFirst("0x", ""),16)));
}
}else{
sb.append(Character.toChars(unicodeIntVale));
}
}else{
sb.append(Character.toChars(unicodeIntVale));
}
if(Character.isHighSurrogate(ch)){
i = i + 2;
continue;
}
else{
i = i + 1;
}
}
realname = sb.toString();
}catch(Exception e) {
e.printStackTrace();
}
return realname;
}
/**
* @Title: changeUnicodeSixToFive
* @Description: 使字符串编码如果是Unicode6的emoji字符则转为Unicode5输出
* @param name
* @return
*/
public String changeUnicodeSixToFive(String name) {
String realname = name;
try{
char[] charArr = name.toCharArray();
StringBuffer sb = new StringBuffer();
int i = 0;
while(i<charArr.length){
char ch = charArr[i];
int unicodeIntVale = 0;
if(Character.isHighSurrogate(ch)){
unicodeIntVale = Character.toCodePoint(ch, charArr[i+1]);
}else{
unicodeIntVale = (int)ch;
}
if( (unicodeIntVale>=MIN_UNICODESIX) && (unicodeIntVale<=MAX_UNICODESIX) ){
String hexBase = Integer.toHexString(unicodeIntVale).toUpperCase();
String trans = propValue.getProperty("0x"+hexBase);
if(trans!=null){
sb.append(Character.toChars(Integer.parseInt(trans.replaceFirst("\\\\u", ""),16)));
}else{
sb.append(Character.toChars(unicodeIntVale));
}
}else{
sb.append(Character.toChars(unicodeIntVale));
}
if(Character.isHighSurrogate(ch)){
i = i + 2;
continue;
}else{
i = i + 1;
}
}
realname = sb.toString();
}catch(Exception e) {
e.printStackTrace();
}
return realname;
}
public static String utf8ToUnicode(String inStr) {
char[] myBuffer = inStr.toCharArray();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < inStr.length(); i++) {
UnicodeBlock ub = UnicodeBlock.of(myBuffer[i]);
if(ub == UnicodeBlock.BASIC_LATIN){
sb.append(inStr);
}else if(ub == UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS){
int j = (int) myBuffer[i] - 65248;
sb.append((char)j);
}else{
int s = (int) myBuffer[i];
// System.out.println(s);
if(s<0)
s = s+2^32;
String hexS = Integer.toHexString(s);
String unicode = "\\u"+hexS.toUpperCase();
sb.append(unicode);
}
}
return sb.toString();
}
}
分享到:
相关推荐
(emoji表情) unicode5与unicode5互换.zip
emoji表情unicode数据库
处理emoji表情 js unicode转码解码方法封装类,自己项目中使用的东西 处理emoji表情 js unicode转码解码方法封装类,自己项目中使用的东西
一个用于管理Android使用的unicode的emoji表情的SQLite数据库
部分emoji表情的unicode编码数据库
包括了各个系统下(apple、android、twitter)不同的表情图片,以及表情的unicode编码
1、开源案例源码,刚好找到,里面自己优化了一下脚本 2、适用于微信登录含有Emoji表情进行处理显示
移动前端手机输入法自带emoji表情字符处理. 处理emoji表情js 转码解码封装类
通用emoji表情包与JSON
开始做的时候,我是通过Unicode对emoji的表情一个一个的读取,但有些表情他们分布的比较乱,而且对应有的是两个Unicode组合而成(比如国旗),在转换之间会挺麻烦的,而且不同的版本显示的内容不一样。后面我把所有...
抖音官方emoji表情,emoji格式为webp。如果需要其他格式可以使用“格式工厂”转换一下。http://www.pcgeshi.com/
解压后打开index.html页面可直接查看该插件效果,若需要在其他页面引用该插件,只需参照index.html内的引入方法
判断字符串是否包含emoji表情
109个微信自带的emoji表情
467个emoji的文件和编码表数据 包括Unicode编码,UTF8编码,UTF16编码,SBUnicode编码
微信最新Emoji表情149个png打包.zip
emoji表情与中文对应,内容举例:“咧开嘴眼睛弯起的笑脸">【这里是一个emoji表情,资源描述不让放】</td><td class="emoji" title="【这里是一个emoji表情,资源描述不让放】 &#x1f603;”、“'【这里是一个...
Emoji表情全部图片(PNG)资源,总共3175张,尺寸72x72,资源收集于2020年10月6日。
让 Windows 7 显示彩色 Emoji 表情符号
本工具类包含了Emoji表情的转码和解码 包括了通过url获取文件大小的功能