本文整理汇总了Java中org.apache.commons.lang3.text.translate.LookupTranslator类的典型用法代码示例。如果您正苦于以下问题:Java LookupTranslator类的具体用法?Java LookupTranslator怎么用?Java LookupTranslator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LookupTranslator类属于org.apache.commons.lang3.text.translate包,在下文中一共展示了LookupTranslator类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: escapeJava
import org.apache.commons.lang3.text.translate.LookupTranslator; //导入依赖的package包/类
private String escapeJava(String str, boolean unicode) {
CharSequenceTranslator tr = new LookupTranslator(new String[][] {
{ "\"", "\\\"" }, { "\\", "\\\\" } })
.with(new CharSequenceTranslator[] { new LookupTranslator(
EntityArrays.JAVA_CTRL_CHARS_ESCAPE()) });
if (unicode)
tr = tr.with(new CharSequenceTranslator[] { UnicodeEscaper
.outsideOf(32, 127) });
return tr.translate(str);
}
示例2: unescapeEntities
import org.apache.commons.lang3.text.translate.LookupTranslator; //导入依赖的package包/类
/**
* Unescapes special entity char sequences like < to its UTF-8 representation.
* All ISO-8859-1, HTML4 and Basic entities will be translated.
*
* @param text the text that will be unescaped
* @return the unescaped version of the string text
*/
public static String unescapeEntities(String text) {
CharSequenceTranslator iso = new LookupTranslator(EntityArrays.ISO8859_1_UNESCAPE());
CharSequenceTranslator basic = new LookupTranslator(EntityArrays.BASIC_UNESCAPE());
//CharSequenceTranslator html4 = new LookupTranslator(EntityArrays.HTML40_EXTENDED_UNESCAPE());
return StringEscapeUtils.unescapeHtml4(iso.translate(basic.translate(text)));
}