Last active
December 20, 2015 05:08
-
-
Save gjcourt/6075630 to your computer and use it in GitHub Desktop.
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
/** | |
* Parse the query string portion of a string containing a URI or URL. | |
*/ | |
def parseUri(uri: String): Map[String, Seq[String]] = { | |
var params = collection.mutable.HashMap[String, Seq[String]]() | |
val parts = uri split "\\?" | |
if (parts.length > 1) { | |
val query = parts(1) | |
for (param <- query split "&") { | |
val pair = param split "=" | |
val key = URLDecoder.decode(pair(0), "UTF-8") | |
val value = pair.length match { | |
case l if l > 1 => URLDecoder.decode(pair(1), "UTF-8") | |
case _ => "" | |
} | |
params += (key -> Seq(value)) | |
} | |
} | |
HashMap() ++ params | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment