MCPcopy Create free account
hub / github.com/davidgiven/luje / decode

Method decode

lib/java/net/URIEncoderDecoder.java:184–214  ·  view source on GitHub ↗

Decodes the string argument which is assumed to be encoded in the x-www-form-urlencoded MIME content type using the UTF-8 encoding scheme. '%' and two following hex digit characters are converted to the equivalent byte value. All other characters are passed through unmodified. e.g. "

(String s)

Source from the content-addressed store, hash-verified

182 * @return java.lang.String The decoded version.
183 */
184 static String decode(String s) throws UnsupportedEncodingException {
185
186 StringBuilder result = new StringBuilder();
187 ByteArrayOutputStream out = new ByteArrayOutputStream();
188 for (int i = 0; i < s.length();) {
189 char c = s.charAt(i);
190 if (c == '%') {
191 out.reset();
192 do {
193 if (i + 2 >= s.length()) {
194 throw new IllegalArgumentException(Messages.getString(
195 "luni.80", i)); //$NON-NLS-1$
196 }
197 int d1 = Character.digit(s.charAt(i + 1), 16);
198 int d2 = Character.digit(s.charAt(i + 2), 16);
199 if (d1 == -1 || d2 == -1) {
200 throw new IllegalArgumentException(Messages.getString(
201 "luni.81", s.substring(i, i + 3), //$NON-NLS-1$
202 String.valueOf(i)));
203 }
204 out.write((byte) ((d1 << 4) + d2));
205 i += 3;
206 } while (i < s.length() && s.charAt(i) == '%');
207 result.append(out.toString(encoding));
208 continue;
209 }
210 result.append(c);
211 i++;
212 }
213 return result.toString();
214 }
215
216}

Callers 1

decodeMethod · 0.95

Calls 11

resetMethod · 0.95
getStringMethod · 0.95
digitMethod · 0.95
valueOfMethod · 0.95
writeMethod · 0.95
appendMethod · 0.95
toStringMethod · 0.95
toStringMethod · 0.95
lengthMethod · 0.65
charAtMethod · 0.65
substringMethod · 0.45

Tested by

no test coverage detected