Skip to content

Instantly share code, notes, and snippets.

@joni
Created June 19, 2012 19:35
Show Gist options
  • Select an option

  • Save joni/2956080 to your computer and use it in GitHub Desktop.

Select an option

Save joni/2956080 to your computer and use it in GitHub Desktop.

Revisions

  1. joni revised this gist Jun 19, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions STRINGDECODE.sql
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    CREATE FUNCTION STRINGDECODE(str TEXT CHARSET utf8)
    RETURNS text CHARSET utf8
    RETURNS text CHARSET utf8 DETERMINISTIC
    BEGIN
    declare pos int;
    declare escape char(6) charset utf8;
    @@ -9,7 +9,7 @@ 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);
    set pos = locate('\\u', str, pos+1);
    end while;
    return str;
    END
  2. joni created this gist Jun 19, 2012.
    15 changes: 15 additions & 0 deletions STRINGDECODE.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    CREATE FUNCTION STRINGDECODE(str TEXT CHARSET utf8)
    RETURNS text CHARSET utf8
    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);
    end while;
    return str;
    END