com.github.houbb.special.chars.test.data.EmojiTest Maven / Gradle / Ivy
package com.github.houbb.special.chars.test.data;
import com.github.houbb.babel.util.BabelHelper;
import com.github.houbb.heaven.constant.enums.LangEnum;
import com.github.houbb.heaven.support.handler.IHandler;
import com.github.houbb.heaven.util.io.FileUtil;
import com.github.houbb.heaven.util.lang.StringUtil;
import com.github.houbb.heaven.util.util.CollectionUtil;
import org.junit.Ignore;
import org.junit.Test;
import java.util.List;
/**
* project: special-char-EmojiTest
* create on 2020/3/5 22:36
*
* @author binbin.hou
* @since 0.0.1
*/
@Ignore
public class EmojiTest {
@Test
public void initZhTest() {
final String o = "D:\\github\\special-char\\special-char-emoji\\src\\main\\resources\\special_char_emoji.data";
List lines = FileUtil.readAllLines(o);
lines = CollectionUtil.toList(lines, new IHandler() {
@Override
public String handle(String s) {
if(s.startsWith("#")) {
return s;
}
String[] strings = s.split(",");
String emoji = strings[0];
String code = strings[1];
if(s.endsWith(",")) {
// 为空时才获取
String desc = getDesc(code);
String line = emoji+","+code+","+desc;
System.out.println(line);
return line;
} else {
return s;
}
}
});
FileUtil.write(o, lines);
}
@Test
public void trimBlank() {
final String o = "D:\\github\\special-char\\special-char-emoji\\src\\main\\resources\\special_char_emoji.data";
List lines = FileUtil.readAllLines(o);
lines = CollectionUtil.toList(lines, new IHandler() {
@Override
public String handle(String s) {
if(s.startsWith("#")) {
return s;
}
List stringList = StringUtil.splitToList(s, ",");
List trimList = CollectionUtil.toList(stringList, new IHandler() {
@Override
public String handle(String s) {
return s.trim();
}
});
return StringUtil.join(trimList);
}
});
FileUtil.write(o, lines);
}
private String getDesc(final String code) {
try {
return BabelHelper.translate(code, LangEnum.AUTO_DETECT, LangEnum.ZH);
} catch (Exception e) {
e.printStackTrace();
return StringUtil.EMPTY;
}
}
@Test
public void typeEnumTest() {
final String t = "D:\\github\\special-char\\special-char-emoji\\src\\main\\resources\\special_char_emoji.data";
List lines = FileUtil.readAllLines(t);
for(String line : lines) {
if(line.startsWith("#")) {
String en = line.replace("#", "")
.replaceAll("&", "and")
.trim()
.toLowerCase();
String zh = BabelHelper.translate(en, LangEnum.ZH);
//lower
List enList = StringUtil.splitToList(en, " ");
String inOne = StringUtil.join(enList, "_");
//UPPER_CASE("code", "DESC")
System.out.println(String.format("%s(\"%s\", \"%s\"),",
inOne.toUpperCase(), en, zh));
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy