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


Java UnicodeEscaper.escape方法代码示例

本文整理汇总了Java中com.google.common.escape.UnicodeEscaper.escape方法的典型用法代码示例。如果您正苦于以下问题:Java UnicodeEscaper.escape方法的具体用法?Java UnicodeEscaper.escape怎么用?Java UnicodeEscaper.escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.escape.UnicodeEscaper的用法示例。


在下文中一共展示了UnicodeEscaper.escape方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: assertBasicUrlEscaperExceptPercent

import com.google.common.escape.UnicodeEscaper; //导入方法依赖的package包/类
/**
 * Helper to assert common expected behaviour of uri escapers. You should call
 * assertBasicUrlEscaper() unless the escaper explicitly does not escape '%'.
 */
static void assertBasicUrlEscaperExceptPercent(UnicodeEscaper e) {
  // URL escapers should throw null pointer exceptions for null input
  try {
    e.escape((String) null);
    fail("Escaping null string should throw exception");
  } catch (NullPointerException x) {
    // pass
  }

  // All URL escapers should leave 0-9, A-Z, a-z unescaped
  assertUnescaped(e, 'a');
  assertUnescaped(e, 'z');
  assertUnescaped(e, 'A');
  assertUnescaped(e, 'Z');
  assertUnescaped(e, '0');
  assertUnescaped(e, '9');

  // Unreserved characters used in java.net.URLEncoder
  assertUnescaped(e, '-');
  assertUnescaped(e, '_');
  assertUnescaped(e, '.');
  assertUnescaped(e, '*');

  assertEscaping(e, "%00", '\u0000');       // nul
  assertEscaping(e, "%7F", '\u007f');       // del
  assertEscaping(e, "%C2%80", '\u0080');    // xx-00010,x-000000
  assertEscaping(e, "%DF%BF", '\u07ff');    // xx-11111,x-111111
  assertEscaping(e, "%E0%A0%80", '\u0800'); // xxx-0000,x-100000,x-00,0000
  assertEscaping(e, "%EF%BF%BF", '\uffff'); // xxx-1111,x-111111,x-11,1111
  assertUnicodeEscaping(e, "%F0%90%80%80", '\uD800', '\uDC00');
  assertUnicodeEscaping(e, "%F4%8F%BF%BF", '\uDBFF', '\uDFFF');

  assertEquals("", e.escape(""));
  assertEquals("safestring", e.escape("safestring"));
  assertEquals("embedded%00null", e.escape("embedded\0null"));
  assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar"));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:42,代码来源:UrlEscapersTest.java

示例2: assertBasicUrlEscaperExceptPercent

import com.google.common.escape.UnicodeEscaper; //导入方法依赖的package包/类
/**
 * Helper to assert common expected behaviour of uri escapers. You should call
 * assertBasicUrlEscaper() unless the escaper explicitly does not escape '%'.
 */
static void assertBasicUrlEscaperExceptPercent(UnicodeEscaper e) {
  // URL escapers should throw null pointer exceptions for null input
  try {
    e.escape((String) null);
    fail("Escaping null string should throw exception");
  } catch (NullPointerException x) {
    // pass
  }

  // All URL escapers should leave 0-9, A-Z, a-z unescaped
  assertUnescaped(e, 'a');
  assertUnescaped(e, 'z');
  assertUnescaped(e, 'A');
  assertUnescaped(e, 'Z');
  assertUnescaped(e, '0');
  assertUnescaped(e, '9');

  // Unreserved characters used in java.net.URLEncoder
  assertUnescaped(e, '-');
  assertUnescaped(e, '_');
  assertUnescaped(e, '.');
  assertUnescaped(e, '*');

  assertEscaping(e, "%00", '\u0000'); // nul
  assertEscaping(e, "%7F", '\u007f'); // del
  assertEscaping(e, "%C2%80", '\u0080'); // xx-00010,x-000000
  assertEscaping(e, "%DF%BF", '\u07ff'); // xx-11111,x-111111
  assertEscaping(e, "%E0%A0%80", '\u0800'); // xxx-0000,x-100000,x-00,0000
  assertEscaping(e, "%EF%BF%BF", '\uffff'); // xxx-1111,x-111111,x-11,1111
  assertUnicodeEscaping(e, "%F0%90%80%80", '\uD800', '\uDC00');
  assertUnicodeEscaping(e, "%F4%8F%BF%BF", '\uDBFF', '\uDFFF');

  assertEquals("", e.escape(""));
  assertEquals("safestring", e.escape("safestring"));
  assertEquals("embedded%00null", e.escape("embedded\0null"));
  assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar"));
}
 
开发者ID:google,项目名称:guava,代码行数:42,代码来源:UrlEscapersTest.java


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