本文整理汇总了Java中com.google.common.escape.UnicodeEscaper类的典型用法代码示例。如果您正苦于以下问题:Java UnicodeEscaper类的具体用法?Java UnicodeEscaper怎么用?Java UnicodeEscaper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnicodeEscaper类属于com.google.common.escape包,在下文中一共展示了UnicodeEscaper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUrlFormParameterEscaper
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
public void testUrlFormParameterEscaper() {
UnicodeEscaper e = (UnicodeEscaper) urlFormParameterEscaper();
// Verify that these are the same escaper (as documented)
assertSame(e, urlFormParameterEscaper());
assertBasicUrlEscaper(e);
/*
* Specified as safe by RFC 2396 but not by java.net.URLEncoder. These tests will start failing
* when the escaper is made compliant with RFC 2396, but that's a good thing (just change them
* to assertUnescaped).
*/
assertEscaping(e, "%21", '!');
assertEscaping(e, "%28", '(');
assertEscaping(e, "%29", ')');
assertEscaping(e, "%7E", '~');
assertEscaping(e, "%27", '\'');
// Plus for spaces
assertEscaping(e, "+", ' ');
assertEscaping(e, "%2B", '+');
assertEquals("safe+with+spaces", e.escape("safe with spaces"));
assertEquals("foo%40bar.com", e.escape("[email protected]"));
}
示例2: assertPathEscaper
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
static void assertPathEscaper(UnicodeEscaper e) {
assertBasicUrlEscaper(e);
assertUnescaped(e, '!');
assertUnescaped(e, '\'');
assertUnescaped(e, '(');
assertUnescaped(e, ')');
assertUnescaped(e, '~');
assertUnescaped(e, ':');
assertUnescaped(e, '@');
// Don't use plus for spaces
assertEscaping(e, "%20", ' ');
assertEquals("safe%20with%20spaces", e.escape("safe with spaces"));
assertEquals("[email protected]", e.escape("[email protected]"));
}
示例3: testSimpleEscaper
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
/** Tests that the simple escaper treats 0-9, a-z and A-Z as safe */
public void testSimpleEscaper() {
UnicodeEscaper e = new PercentEscaper("", false);
for (char c = 0; c < 128; c++) {
if ((c >= '0' && c <= '9') ||
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z')) {
assertUnescaped(e, c);
} else {
assertEscaping(e, escapeAscii(c), c);
}
}
// Testing mutlibyte escape sequences
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');
// simple string tests
assertEquals("", e.escape(""));
assertEquals("safestring", e.escape("safestring"));
assertEquals("embedded%00null", e.escape("embedded\0null"));
assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar"));
}
示例4: testPlusForSpace
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
/** Tests the various ways that the space character can be handled */
public void testPlusForSpace() {
UnicodeEscaper basicEscaper = new PercentEscaper("", false);
UnicodeEscaper plusForSpaceEscaper = new PercentEscaper("", true);
UnicodeEscaper spaceEscaper = new PercentEscaper(" ", false);
assertEquals("string%20with%20spaces",
basicEscaper.escape("string with spaces"));
assertEquals("string+with+spaces",
plusForSpaceEscaper.escape("string with spaces"));
assertEquals("string with spaces",
spaceEscaper.escape("string with spaces"));
}
示例5: testCustomEscaper
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
/** Tests that if we add extra 'safe' characters they remain unescaped */
public void testCustomEscaper() {
UnicodeEscaper e = new PercentEscaper("+*/-", false);
for (char c = 0; c < 128; c++) {
if ((c >= '0' && c <= '9') ||
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
"+*/-".indexOf(c) >= 0) {
assertUnescaped(e, c);
} else {
assertEscaping(e, escapeAscii(c), c);
}
}
}
示例6: 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"));
}
示例7: testUrlFragmentEscaper
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
public void testUrlFragmentEscaper() {
UnicodeEscaper e = (UnicodeEscaper) urlFragmentEscaper();
assertUnescaped(e, '+');
assertUnescaped(e, '/');
assertUnescaped(e, '?');
assertPathEscaper(e);
}
示例8: assertUnicodeEscaping
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
/**
* Asserts that a Unicode escaper escapes the given hi/lo surrogate pair into the expected string.
*
* @param escaper the non-null escaper to test
* @param expected the expected output string
* @param hi the high surrogate pair character
* @param lo the low surrogate pair character
*/
public static void assertUnicodeEscaping(
UnicodeEscaper escaper, String expected, char hi, char lo) {
int cp = Character.toCodePoint(hi, lo);
String escaped = computeReplacement(escaper, cp);
Assert.assertNotNull(escaped);
Assert.assertEquals(expected, escaped);
}
示例9: testSimpleEscaper
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
/** Tests that the simple escaper treats 0-9, a-z and A-Z as safe */
public void testSimpleEscaper() {
UnicodeEscaper e = new PercentEscaper("", false);
for (char c = 0; c < 128; c++) {
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
assertUnescaped(e, c);
} else {
assertEscaping(e, escapeAscii(c), c);
}
}
// Testing mutlibyte escape sequences
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');
// simple string tests
assertEquals("", e.escape(""));
assertEquals("safestring", e.escape("safestring"));
assertEquals("embedded%00null", e.escape("embedded\0null"));
assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar"));
}
示例10: testPlusForSpace
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
/** Tests the various ways that the space character can be handled */
public void testPlusForSpace() {
UnicodeEscaper basicEscaper = new PercentEscaper("", false);
UnicodeEscaper plusForSpaceEscaper = new PercentEscaper("", true);
UnicodeEscaper spaceEscaper = new PercentEscaper(" ", false);
assertEquals("string%20with%20spaces", basicEscaper.escape("string with spaces"));
assertEquals("string+with+spaces", plusForSpaceEscaper.escape("string with spaces"));
assertEquals("string with spaces", spaceEscaper.escape("string with spaces"));
}
示例11: testCustomEscaper
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
/** Tests that if we add extra 'safe' characters they remain unescaped */
public void testCustomEscaper() {
UnicodeEscaper e = new PercentEscaper("+*/-", false);
for (char c = 0; c < 128; c++) {
if ((c >= '0' && c <= '9')
|| (c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')
|| "+*/-".indexOf(c) >= 0) {
assertUnescaped(e, c);
} else {
assertEscaping(e, escapeAscii(c), c);
}
}
}
示例12: 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"));
}
示例13: testCustomEscaper_withpercent
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
/** Tests that if specify '%' as safe the result is an idempotent escaper. */
public void testCustomEscaper_withpercent() {
UnicodeEscaper e = new PercentEscaper("%", false);
assertEquals("foo%7Cbar", e.escape("foo|bar"));
assertEquals("foo%7Cbar", e.escape("foo%7Cbar")); // idempotent
}
示例14: assertBasicUrlEscaper
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
static void assertBasicUrlEscaper(UnicodeEscaper e) {
assertBasicUrlEscaperExceptPercent(e);
// The escape character must always be escaped
assertEscaping(e, "%25", '%');
}
示例15: testUrlPathSegmentEscaper
import com.google.common.escape.UnicodeEscaper; //导入依赖的package包/类
public void testUrlPathSegmentEscaper() {
UnicodeEscaper e = (UnicodeEscaper) urlPathSegmentEscaper();
assertPathEscaper(e);
assertUnescaped(e, '+');
}