当前位置: 首页>>代码示例>>Java>>正文


Java CharSequenceTranslator类代码示例

本文整理汇总了Java中org.apache.commons.lang3.text.translate.CharSequenceTranslator的典型用法代码示例。如果您正苦于以下问题:Java CharSequenceTranslator类的具体用法?Java CharSequenceTranslator怎么用?Java CharSequenceTranslator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CharSequenceTranslator类属于org.apache.commons.lang3.text.translate包,在下文中一共展示了CharSequenceTranslator类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testEscapeXmlAllCharacters

import org.apache.commons.lang3.text.translate.CharSequenceTranslator; //导入依赖的package包/类
@Test
public void testEscapeXmlAllCharacters() {
    // http://www.w3.org/TR/xml/#charsets says:
    // Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character,
    // excluding the surrogate blocks, FFFE, and FFFF. */
    final CharSequenceTranslator escapeXml = StringEscapeUtils.ESCAPE_XML
            .with(NumericEntityEscaper.below(9), NumericEntityEscaper.between(0xB, 0xC), NumericEntityEscaper.between(0xE, 0x19),
                    NumericEntityEscaper.between(0xD800, 0xDFFF), NumericEntityEscaper.between(0xFFFE, 0xFFFF), NumericEntityEscaper.above(0x110000));

    assertEquals("�", escapeXml.translate("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008"));
    assertEquals("\t", escapeXml.translate("\t")); // 0x9
    assertEquals("\n", escapeXml.translate("\n")); // 0xA
    assertEquals("", escapeXml.translate("\u000B\u000C"));
    assertEquals("\r", escapeXml.translate("\r")); // 0xD
    assertEquals("Hello World! Ain't this great?", escapeXml.translate("Hello World! Ain't this great?"));
    assertEquals("", escapeXml.translate("\u000E\u000F\u0018\u0019"));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:StringEscapeUtilsTest.java

示例2: escapeJava

import org.apache.commons.lang3.text.translate.CharSequenceTranslator; //导入依赖的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);
}
 
开发者ID:yaoxinghuo,项目名称:StringEditEclipse,代码行数:11,代码来源:StringUtils.java

示例3: escapeJavaStyleString

import org.apache.commons.lang3.text.translate.CharSequenceTranslator; //导入依赖的package包/类
/**
 * @param out write to receieve the escaped string
 * @param str String to escape values in, may be null
 * @param escapeSingleQuote escapes single quotes if <code>true</code>
 * @param escapeForwardSlash TODO
 * @throws IOException if an IOException occurs
 */
private static void escapeJavaStyleString(Writer out, String str, boolean escapeSingleQuote,
                                          boolean escapeForwardSlash) throws IOException {
    if (out == null) {
        throw new IllegalArgumentException("The Writer must not be null");
    }
    if (str == null) {
        return;
    }
    int sz;
    sz = str.length();
    for (int i = 0; i < sz; i++) {
        char ch = str.charAt(i);
        // "[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFD]"
        // handle unicode
        if (ch > 0xFFFD) {
            out.write("\\u" + CharSequenceTranslator.hex(ch));
        } else if (ch > 0xD7FF && ch < 0xE000) {
            out.write("\\u" + CharSequenceTranslator.hex(ch));
        } else if (ch > 0x7E && ch != 0x85 && ch < 0xA0) {
            out.write("\\u00" + CharSequenceTranslator.hex(ch));
        } else if (ch < 32) {
            switch (ch) {
                case '\t' :
                    out.write('\\');
                    out.write('t');
                    break;
                case '\n' :
                    out.write('\\');
                    out.write('n');
                    break;
                case '\r' :
                    out.write('\\');
                    out.write('r');
                    break;
                default :
                    if (ch > 0xf) {
                        out.write("\\u00" + CharSequenceTranslator.hex(ch));
                    } else {
                        out.write("\\u000" + CharSequenceTranslator.hex(ch));
                    }
                    break;
            }
        } else {
            switch (ch) {
                case '\'' :
                    if (escapeSingleQuote) {
                        out.write('\\');
                    }
                    out.write('\'');
                    break;
                case '"' :
                    out.write('\\');
                    out.write('"');
                    break;
                case '\\' :
                    out.write('\\');
                    out.write('\\');
                    break;
                case '/' :
                    if (escapeForwardSlash) {
                        out.write('\\');
                    }
                    out.write('/');
                    break;
                default :
                    out.write(ch);
                    break;
            }
        }
    }
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:79,代码来源:YamlStringEscapeUtils.java

示例4: getArgumentEscaper

import org.apache.commons.lang3.text.translate.CharSequenceTranslator; //导入依赖的package包/类
CharSequenceTranslator getArgumentEscaper() {
    return argumentEscaper;
}
 
开发者ID:wildfly-extras,项目名称:sunstone,代码行数:4,代码来源:ExecBuilderOptions.java

示例5: setTranslator

import org.apache.commons.lang3.text.translate.CharSequenceTranslator; //导入依赖的package包/类
public void setTranslator(CharSequenceTranslator translator) {
  this.translator = translator;
}
 
开发者ID:wnameless,项目名称:json-flattener,代码行数:4,代码来源:JsonifyLinkedHashMap.java

示例6: testEscapeXmlSupplementaryCharacters

import org.apache.commons.lang3.text.translate.CharSequenceTranslator; //导入依赖的package包/类
/**
 * Tests Supplementary characters. 
 * <p>
 * From http://www.w3.org/International/questions/qa-escapes
 * </p>
 * <blockquote>
 * Supplementary characters are those Unicode characters that have code points higher than the characters in
 * the Basic Multilingual Plane (BMP). In UTF-16 a supplementary character is encoded using two 16-bit surrogate code points from the
 * BMP. Because of this, some people think that supplementary characters need to be represented using two escapes, but this is incorrect
 * - you must use the single, code point value for that character. For example, use &#x233B4; rather than &#xD84C;&#xDFB4;.
 * </blockquote>
 * @see <a href="http://www.w3.org/International/questions/qa-escapes">Using character escapes in markup and CSS</a>
 * @see <a href="https://issues.apache.org/jira/browse/LANG-728">LANG-728</a>
 */
@Test
public void testEscapeXmlSupplementaryCharacters() {
    final CharSequenceTranslator escapeXml = 
        StringEscapeUtils.ESCAPE_XML.with( NumericEntityEscaper.between(0x7f, Integer.MAX_VALUE) );

    assertEquals("Supplementary character must be represented using a single escape", "&#144308;",
            escapeXml.translate("\uD84C\uDFB4"));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:StringEscapeUtilsTest.java

示例7: testEscapeXmlSupplementaryCharacters

import org.apache.commons.lang3.text.translate.CharSequenceTranslator; //导入依赖的package包/类
/**
 * Tests Supplementary characters. 
 * <p>
 * From http://www.w3.org/International/questions/qa-escapes
 * </p>
 * <blockquote>
 * Supplementary characters are those Unicode characters that have code points higher than the characters in
 * the Basic Multilingual Plane (BMP). In UTF-16 a supplementary character is encoded using two 16-bit surrogate code points from the
 * BMP. Because of this, some people think that supplementary characters need to be represented using two escapes, but this is incorrect
 * - you must use the single, code point value for that character. For example, use &#x233B4; rather than &#xD84C;&#xDFB4;.
 * </blockquote>
 * @see <a href="http://www.w3.org/International/questions/qa-escapes">Using character escapes in markup and CSS</a>
 * @see <a href="https://issues.apache.org/jira/browse/LANG-728">LANG-728</a>
 */
@Test
public void testEscapeXmlSupplementaryCharacters() {
    CharSequenceTranslator escapeXml = 
        StringEscapeUtils.ESCAPE_XML.with( NumericEntityEscaper.between(0x7f, Integer.MAX_VALUE) );

    assertEquals("Supplementary character must be represented using a single escape", "&#144308;",
            escapeXml.translate("\uD84C\uDFB4"));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:StringEscapeUtilsTest.java

示例8: unescapeEntities

import org.apache.commons.lang3.text.translate.CharSequenceTranslator; //导入依赖的package包/类
/**
 * Unescapes special entity char sequences like &lt; 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)));
}
 
开发者ID:wikimedia,项目名称:citolytics,代码行数:14,代码来源:WikiSimStringUtils.java

示例9: testEscapeXmlSupplementaryCharacters

import org.apache.commons.lang3.text.translate.CharSequenceTranslator; //导入依赖的package包/类
/**
 * Tests Supplementary characters.
 * <p>
 * From http://www.w3.org/International/questions/qa-escapes
 * </p>
 * <blockquote>
 * Supplementary characters are those Unicode characters that have code points higher than the characters in
 * the Basic Multilingual Plane (BMP). In UTF-16 a supplementary character is encoded using two 16-bit surrogate code points from the
 * BMP. Because of this, some people think that supplementary characters need to be represented using two escapes, but this is incorrect
 * - you must use the single, code point value for that character. For example, use &amp;&#35;x233B4&#59; rather than
 * &amp;&#35;xD84C&#59;&amp;&#35;xDFB4&#59;.
 * </blockquote>
 * @see <a href="http://www.w3.org/International/questions/qa-escapes">Using character escapes in markup and CSS</a>
 * @see <a href="https://issues.apache.org/jira/browse/LANG-728">LANG-728</a>
 */
@Test
public void testEscapeXmlSupplementaryCharacters() {
    final CharSequenceTranslator escapeXml =
        StringEscapeUtils.ESCAPE_XML.with( NumericEntityEscaper.between(0x7f, Integer.MAX_VALUE) );

    assertEquals("Supplementary character must be represented using a single escape", "&#144308;",
            escapeXml.translate("\uD84C\uDFB4"));

    assertEquals("Supplementary characters mixed with basic characters should be encoded correctly", "a b c &#144308;",
                    escapeXml.translate("a b c \uD84C\uDFB4"));
}
 
开发者ID:ManfredTremmel,项目名称:gwt-commons-lang3,代码行数:27,代码来源:StringEscapeUtilsTest.java


注:本文中的org.apache.commons.lang3.text.translate.CharSequenceTranslator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。