Remove unnecessary 'return's / Clean up QueryStringDecoder

This commit is contained in:
Trustin Lee 2012-11-12 09:15:33 +09:00
parent a76cdc26d0
commit 4cd7fb1abb

View File

@ -15,6 +15,8 @@
*/ */
package org.jboss.netty.handler.codec.http; package org.jboss.netty.handler.codec.http;
import org.jboss.netty.util.CharsetUtil;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.net.URLDecoder; import java.net.URLDecoder;
@ -25,8 +27,6 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jboss.netty.util.CharsetUtil;
/** /**
* Splits an HTTP query string into a path string and key-value parameter pairs. * Splits an HTTP query string into a path string and key-value parameter pairs.
* This decoder is for one time use only. Create a new instance for each URI: * This decoder is for one time use only. Create a new instance for each URI:
@ -235,7 +235,7 @@ public class QueryStringDecoder {
String name = null; String name = null;
int pos = 0; // Beginning of the unprocessed region int pos = 0; // Beginning of the unprocessed region
int i; // End of the unprocessed region int i; // End of the unprocessed region
char c = 0; // Current character char c; // Current character
for (i = 0; i < s.length(); i++) { for (i = 0; i < s.length(); i++) {
c = s.charAt(i); c = s.charAt(i);
if (c == '=' && name == null) { if (c == '=' && name == null) {
@ -263,18 +263,12 @@ public class QueryStringDecoder {
if (pos != i) { // Are there characters we haven't dealt with? if (pos != i) { // Are there characters we haven't dealt with?
if (name == null) { // Yes and we haven't seen any `='. if (name == null) { // Yes and we haven't seen any `='.
if (!addParam(params, decodeComponent(s.substring(pos, i), charset), "")) { addParam(params, decodeComponent(s.substring(pos, i), charset), "");
return;
}
} else { // Yes and this must be the last value. } else { // Yes and this must be the last value.
if (!addParam(params, name, decodeComponent(s.substring(pos, i), charset))) { addParam(params, name, decodeComponent(s.substring(pos, i), charset));
return;
}
} }
} else if (name != null) { // Have we seen a name without value? } else if (name != null) { // Have we seen a name without value?
if (!addParam(params, name, "")) { addParam(params, name, "");
return;
}
} }
} }
@ -369,7 +363,9 @@ public class QueryStringDecoder {
if (c == '%') { if (c == '%') {
buf[pos++] = '%'; // "%%" -> "%" buf[pos++] = '%'; // "%%" -> "%"
break; break;
} else if (i == size - 1) { }
if (i == size - 1) {
throw new IllegalArgumentException("partial escape" throw new IllegalArgumentException("partial escape"
+ " sequence at end of string: " + s); + " sequence at end of string: " + s);
} }
@ -391,7 +387,7 @@ public class QueryStringDecoder {
try { try {
return new String(buf, 0, pos, charset.name()); return new String(buf, 0, pos, charset.name());
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("unsupported encoding: " + charset.name()); throw new IllegalArgumentException("unsupported encoding: " + charset.name(), e);
} }
} }