Created
June 6, 2009 13:43
-
-
Save pokutuna/124853 to your computer and use it in GitHub Desktop.
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
| module Latin1Conv | |
| require 'cgi' | |
| LATIN1_CONVERT_TABLE = { | |
| ' ' => ' ', | |
| '¡' => '¡', | |
| '¢' => '¢', | |
| '£' => '£', | |
| '¤' => '¤', | |
| '¥' => '¥', | |
| '¦' => '¦', | |
| '§' => '§', | |
| '¨' => '¨', | |
| '©' => '©', | |
| 'ª' => 'ª', | |
| '«' => '«', | |
| '¬' => '¬', | |
| '­' => '­', | |
| '®' => '®', | |
| '¯' => '¯', | |
| '°' => '°', | |
| '±' => '±', | |
| '²' => '²', | |
| '³' => '³', | |
| '´' => '´', | |
| 'µ' => 'µ', | |
| '¶' => '¶', | |
| '·' => '·', | |
| '¸' => '¸', | |
| '¹' => '¹', | |
| 'º' => 'º', | |
| '»' => '»', | |
| '¼' => '¼', | |
| '½' => '½', | |
| '¾' => '¾', | |
| '¿' => '¿', | |
| 'À' => 'À', | |
| 'Á' => 'Á', | |
| 'Â' => 'Â', | |
| 'Ã' => 'Ã', | |
| 'Ä' => 'Ä', | |
| 'Å' => 'Å', | |
| 'Æ' => 'Æ', | |
| 'Ç' => 'Ç', | |
| 'È' => 'È', | |
| 'É' => 'É', | |
| 'Ê' => 'Ê', | |
| 'Ë' => 'Ë', | |
| 'Ì' => 'Ì', | |
| 'Í' => 'Í', | |
| 'Î' => 'Î', | |
| 'Ï' => 'Ï', | |
| 'Ð' => 'Ð', | |
| 'Ñ' => 'Ñ', | |
| 'Ò' => 'Ò', | |
| 'Ó' => 'Ó', | |
| 'Ô' => 'Ô', | |
| 'Õ' => 'Õ', | |
| 'Ö' => 'Ö', | |
| '×' => '×', | |
| 'Ø' => 'Ø', | |
| 'Ù' => 'Ù', | |
| 'Ú' => 'Ú', | |
| 'Û' => 'Û', | |
| 'Ü' => 'Ü', | |
| 'Ý' => 'Ý', | |
| 'Þ' => 'Þ', | |
| 'ß' => 'ß', | |
| 'à' => 'à', | |
| 'á' => 'á', | |
| 'â' => 'â', | |
| 'ã' => 'ã', | |
| 'ä' => 'ä', | |
| 'å' => 'å', | |
| 'æ' => 'æ', | |
| 'ç' => 'ç', | |
| 'è' => 'è', | |
| 'é' => 'é', | |
| 'ê' => 'ê', | |
| 'ë' => 'ë', | |
| 'ì' => 'ì', | |
| 'í' => 'í', | |
| 'î' => 'î', | |
| 'ï' => 'ï', | |
| 'ð' => 'ð', | |
| 'ñ' => 'ñ', | |
| 'ò' => 'ò', | |
| 'ó' => 'ó', | |
| 'ô' => 'ô', | |
| 'õ' => 'õ', | |
| 'ö' => 'ö', | |
| '÷' => '÷', | |
| 'ø' => 'ø', | |
| 'ù' => 'ù', | |
| 'ú' => 'ú', | |
| 'û' => 'û', | |
| 'ü' => 'ü', | |
| 'ý' => 'ý', | |
| 'þ' => 'þ', | |
| 'ÿ' => 'ÿ' | |
| } | |
| def unescapeHTML | |
| return CGI.unescapeHTML(self.gsub(/(&#\d+;)/){|pat| LATIN1_CONVERT_TABLE[pat]||pat}) | |
| end | |
| end | |
| if $0 == __FILE__ then | |
| class String; include Latin1Conv; end | |
| latin1 = ' ¥ªÈÿ' | |
| puts latin1 | |
| puts latin1.unescapeHTML | |
| end |
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
|  ¥ªÈÿ | |
| ¥ªÈÿ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment