Skip to content

Instantly share code, notes, and snippets.

@icambridge
Created March 25, 2012 16:16
Show Gist options
  • Save icambridge/2197977 to your computer and use it in GitHub Desktop.
Save icambridge/2197977 to your computer and use it in GitHub Desktop.
Uri Escape
object Uri {
def escape(unsafe: String) = {
val alphabet = List[String]("a","b","c","e","f","g","h","i","j","k","l","m","n",
"o","p","q","r","s","t","u","v","w","x","y","z")
var safe = ""
unsafe.split("").foreach { char =>
if (alphabet.indexOf(char.toLowerCase) == -1 && char.forall(_.isDigit) == false) {
safe += "%"
safe += Integer.toHexString(char.charAt(0).toInt)
} else {
safe += char
}
}
safe
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment