Forked from antyblin/mysql-decode-unicode-sequences-function
Created
March 2, 2018 03:20
-
-
Save vcancy/a0f49022c62f10f0d85beb3bbc125ad3 to your computer and use it in GitHub Desktop.
MySQL Function for decoding unicode escapes (original here: http://stackoverflow.com/a/11108219)
This file contains 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
DELIMITER // | |
CREATE FUNCTION STRINGDECODE(str TEXT CHARSET utf8) | |
RETURNS text CHARSET utf8 DETERMINISTIC | |
BEGIN | |
declare pos int; | |
declare escape char(6) charset utf8; | |
declare unescape char(3) charset utf8; | |
set pos = locate('\\u', str); | |
while pos > 0 do | |
set escape = substring(str, pos, 6); | |
set unescape = char(conv(substring(escape,3),16,10) using ucs2); | |
set str = replace(str, escape, unescape); | |
set pos = locate('\\u', str, pos+1); | |
end while; | |
return str; | |
END// | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment