Skip to content

Instantly share code, notes, and snippets.

@jewer
Last active December 30, 2015 02:29
Show Gist options
  • Select an option

  • Save jewer/7763016 to your computer and use it in GitHub Desktop.

Select an option

Save jewer/7763016 to your computer and use it in GitHub Desktop.
hack to get querystring values
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