Skip to content

Instantly share code, notes, and snippets.

@phajduk
Created December 4, 2015 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phajduk/b0442ae2fcffb6f1ce2d to your computer and use it in GitHub Desktop.
Save phajduk/b0442ae2fcffb6f1ce2d to your computer and use it in GitHub Desktop.
UrlHelper
public class UrlHelper {
public static Map<String, String> splitQuery(String query) {
Map<String, String> queryPairs = new LinkedHashMap<>();
String[] pairs = query.split("&");
for(String pair : pairs) {
int idx = pair.indexOf("=");
try {
queryPairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
} catch(UnsupportedEncodingException e) {
Timber.e(e, "Problem during parsing query args");
}
}
return queryPairs;
}
public static String decodeStringWithUtf8(String value) {
try {
return URLDecoder.decode(value, "UTF-8");
} catch(UnsupportedEncodingException e) {
return value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment