Created
April 15, 2015 18:43
-
-
Save vrachieru/d1df10eb9d688c35ad2b to your computer and use it in GitHub Desktop.
Percent encoding on string.
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 percentEncoding(text) { | |
def reserved = [32:1, 33:1, 42:1, 34:1, 39:1, 40:1, 41:1, 59:1, 58:1, 64:1, 38:1, 61:1, 43:1, 36:1, 33:1, 47:1, 63:1, 37:1, 91:1, 93:1, 35:1]; | |
def encoded = text.collect { letter -> | |
reserved[(int)letter] ? "%" + Integer.toHexString((int)letter).toString().toUpperCase() : letter; | |
} | |
return encoded.join(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment