Last active
December 30, 2015 02:29
-
-
Save jewer/7763016 to your computer and use it in GitHub Desktop.
hack to get querystring values
This file contains hidden or 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
| def parse(uri: String) : Map[String,Seq[String]] = { | |
| if (uri == null || uri.isEmpty) { | |
| return Map() | |
| } | |
| def parsePairs(pair: String) : (String, String) = { | |
| val bits = pair.decodeUrl.split("=") | |
| (bits(0), bits(1)) | |
| } | |
| val qs = uri.split("\\?") | |
| if (qs.size < 2) Map() | |
| else qs.last.split("&").map(parsePairs).groupBy(_._1).mapValues(_.map(_._2).toSeq) | |
| } | |
| } | |
| val outs = parse("google.com?cats=cool&kittens=awesome&cats=stillcool") | |
| System.out.println(outs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment