Other characters, which are Unicode chars that are not US-ASCII, and are not ISO Control or are not ISO Space chars are not preserved. They are converted into their hexidecimal value prepended by '%'. For example: Euro currency symbol -> "%E2%82%AC". Called from URI.toASCIIString() @param s
(String s)
| 148 | * @return java.lang.String the converted string |
| 149 | */ |
| 150 | static String encodeOthers(String s) throws UnsupportedEncodingException { |
| 151 | StringBuilder buf = new StringBuilder(); |
| 152 | for (int i = 0; i < s.length(); i++) { |
| 153 | char ch = s.charAt(i); |
| 154 | if (ch <= 127) { |
| 155 | buf.append(ch); |
| 156 | } else { |
| 157 | byte[] bytes = new String(new char[] { ch }).getBytes(encoding); |
| 158 | for (int j = 0; j < bytes.length; j++) { |
| 159 | buf.append('%'); |
| 160 | buf.append(digits.charAt((bytes[j] & 0xf0) >> 4)); |
| 161 | buf.append(digits.charAt(bytes[j] & 0xf)); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | return buf.toString(); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Decodes the string argument which is assumed to be encoded in the {@code |