fun parseQuerystring(queryString: String?): Map<String, String>? { val map: MutableMap<String, String> = HashMap() if (queryString == null || queryString == "") { return map } val params = queryString.split("&".toRegex()).dropLastWhile { it.isEmpty() } .toTypedArray() for (param in params) { try { val keyValuePair = param.split("=".toRegex(), limit = 2).toTypedArray() val name: String = URLDecoder.decode(keyValuePair[0], "UTF-8") if (name === "") { continue } val value = if (keyValuePair.size > 1) URLDecoder.decode(keyValuePair[1], "UTF-8") else "" map[name] = value } catch (e: UnsupportedEncodingException) { } } return map }
Parse a querystring into a map of key/value pairs .