Created
July 7, 2015 07:54
-
-
Save wyukawa/d7576e00d82e7931f36f to your computer and use it in GitHub Desktop.
urlencode/urldecode
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
| @Nullable | |
| @Description("encode url") | |
| @ScalarFunction | |
| @SqlType(StandardTypes.VARCHAR) | |
| public static Slice urlEncode(@SqlType(StandardTypes.VARCHAR) Slice url, @SqlType(StandardTypes.VARCHAR) Slice enc) | |
| { | |
| if ((url == null) || (enc == null)) { | |
| return null; | |
| } | |
| try { | |
| return slice(URLEncoder.encode(url.toString(UTF_8), enc.toString(UTF_8))); | |
| } | |
| catch (UnsupportedEncodingException e) { | |
| return null; | |
| } | |
| } | |
| @Nullable | |
| @Description("decode url") | |
| @ScalarFunction | |
| @SqlType(StandardTypes.VARCHAR) | |
| public static Slice urlDecode(@SqlType(StandardTypes.VARCHAR) Slice url, @SqlType(StandardTypes.VARCHAR) Slice enc) | |
| { | |
| if ((url == null) || (enc == null)) { | |
| return null; | |
| } | |
| try { | |
| return slice(URLDecoder.decode(url.toString(UTF_8), enc.toString(UTF_8))); | |
| } | |
| catch (UnsupportedEncodingException e) { | |
| return null; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment