Created
December 4, 2015 07:44
-
-
Save phajduk/b0442ae2fcffb6f1ce2d to your computer and use it in GitHub Desktop.
UrlHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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