All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9') and legal characters are converted into their hexidecimal value prepended by '%'. For example: '#' -> %23 Other characters, which are unicode chars that are not US-ASCII, and are not ISO Control or are not ISO Space chars,
(String s, String legal)
| 111 | * @return java.lang.String the converted string |
| 112 | */ |
| 113 | static String quoteIllegal(String s, String legal) |
| 114 | throws UnsupportedEncodingException { |
| 115 | StringBuilder buf = new StringBuilder(); |
| 116 | for (int i = 0; i < s.length(); i++) { |
| 117 | char ch = s.charAt(i); |
| 118 | if ((ch >= 'a' && ch <= 'z') |
| 119 | || (ch >= 'A' && ch <= 'Z') |
| 120 | || (ch >= '0' && ch <= '9') |
| 121 | || legal.indexOf(ch) > -1 |
| 122 | || (ch > 127 && !Character.isSpaceChar(ch) && !Character |
| 123 | .isISOControl(ch))) { |
| 124 | buf.append(ch); |
| 125 | } else { |
| 126 | byte[] bytes = new String(new char[] { ch }).getBytes(encoding); |
| 127 | for (int j = 0; j < bytes.length; j++) { |
| 128 | buf.append('%'); |
| 129 | buf.append(digits.charAt((bytes[j] & 0xf0) >> 4)); |
| 130 | buf.append(digits.charAt(bytes[j] & 0xf)); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | return buf.toString(); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Other characters, which are Unicode chars that are not US-ASCII, and are |
no test coverage detected