#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @author: remy sharp
# @info: http://leftlogic.com/entity-lookup/
# @date: 2007-05-28
# @last updated: 2007-06-04
# @description: finds and returns entity charaters matching 'like' data
# @license: Creative Commons License - ShareAlike http://creativecommons.org/licenses/by-sa/3.0/

class Entities:
    DATA = [
        ['nbsp',    160,  'no-break space = non-breaking space, U+00A0 ISOnum',                                   [u' ', 'space']],
        ['iexcl',   161,  'inverted exclamation mark, U+00A1 ISOnum',                                             [u'¡', 'exclamation', 'mark', '!']],
        ['cent',    162,  'cent sign, U+00A2 ISOnum',                                                             [u'¢', 'cent', 'c']],
        ['pound',   163,  'pound sign, U+00A3 ISOnum',                                                            [u'£', '#', 'pound']],
        ['curren',  164,  'currency sign, U+00A4 ISOnum',                                                         [u'¤', 'currency']],
        ['yen',     165,  'yen sign = yuan sign, U+00A5 ISOnum',                                                  [u'¥', 'yen', 'y']],
        ['brvbar',  166,  'broken bar = broken vertical bar, U+00A6 ISOnum',                                      [u'¦', 'bar', 'vertical', '|']],
        ['sect',    167,  'section sign, U+00A7 ISOnum',                                                          [u'§', 'section', 's']],
        ['uml',     168,  'diaeresis = spacing diaeresis, U+00A8 ISOdia',                                         [u'¨', '"']],
        ['copy',    169,  'copyright sign, U+00A9 ISOnum',                                                        [u'©', '(c)', 'c', 'copyright']],
        ['ordf',    170,  'feminine ordinal indicator, U+00AA ISOnum',                                            [u'ª', 'a']],
        ['laquo',   171,  'left-pointing double angle quotation mark = left pointing guillemet, U+00AB ISOnum',   [u'«', '<', '<<', 'double']],
        ['not',     172,  'not sign, U+00AC ISOnum',                                                              [u'¬', 'not', '-']],
        ['shy',     173,  'soft hyphen = discretionary hyphen, U+00AD ISOnum',                                    [u'­']],
        ['reg',     174,  'registered sign = registered trade mark sign, U+00AE ISOnum',                          [u'®', '(r)', 'r', 'registered']],
        ['macr',    175,  'macron = spacing macron = overline = APL overbar, U+00AF ISOdia',                      [u'¯', '-', 'overline']],
        ['deg',     176,  'degree sign, U+00B0 ISOnum',                                                           [u'°', 'degree', 'o']],
        ['plusmn',  177,  'plus-minus sign = plus-or-minus sign, U+00B1 ISOnum',                                  [u'±', 'plus-minus', '+', '-', '+-']],
        ['sup2',    178,  'superscript two = superscript digit two = squared, U+00B2 ISOnum',                     [u'²', 'superscript', 'two', '2']],
        ['sup3',    179,  'superscript three = superscript digit three = cubed, U+00B3 ISOnum',                   [u'³', 'superscript', 'three', '3']],
        ['acute',   180,  'acute accent = spacing acute, U+00B4 ISOdia',                                          [u'´', 'acute', "'", '`']],
        ['micro',   181,  'micro sign, U+00B5 ISOnum',                                                            [u'µ', 'micro', 'u']],
        ['para',    182,  'pilcrow sign = paragraph sign, U+00B6 ISOnum',                                         [u'¶', 'pilcrow', 'enter', 'return', 'n']],
        ['middot',  183,  'middle dot = Georgian comma = Greek middle dot, U+00B7 ISOnum',                        [u'·', '.', 'middle', 'dot']],
        ['cedil',   184,  'cedilla = spacing cedilla, U+00B8 ISOdia',                                             [u'¸', ',']],
        ['sup1',    185,  'superscript one = superscript digit one, U+00B9 ISOnum',                               [u'¹', '1', 'superscript', 'one']],
        ['ordm',    186,  'masculine ordinal indicator, U+00BA ISOnum',                                           [u'º', 'o', 'ordinal']],
        ['raquo',   187,  'right-pointing double angle quotation mark = right pointing guillemet, U+00BB ISOnum', [u'»', 'right-pointing', 'double', '>', '>>']],
        ['frac14',  188,  'vulgar fraction one quarter = fraction one quarter, U+00BC ISOnum',                    [u'¼', 'fraction', '1/4', 'quarter']],
        ['frac12',  189,  'vulgar fraction one half = fraction one half, U+00BD ISOnum',                          [u'½', 'fraction', 'half', '1/2']],
        ['frac34',  190,  'vulgar fraction three quarters = fraction three quarters, U+00BE ISOnum',              [u'¾', 'fraction', 'quarters', '3/4']],
        ['iquest',  191,  'inverted question mark = turned question mark, U+00BF ISOnum',                         [u'¿', '?', 'question', 'inverted']],
        ['Agrave',  192,  'latin capital letter A with grave = latin capital letter A grave, U+00C0 ISOlat1',     [u'À', 'A', 'grave']],
        ['Aacute',  193,  'latin capital letter A with acute, U+00C1 ISOlat1',                                    [u'Á', 'A', 'acute']],
        ['Acirc',   194,  'latin capital letter A with circumflex, U+00C2 ISOlat1',                               [u'Â', 'A', 'circumflex']],
        ['Atilde',  195,  'latin capital letter A with tilde, U+00C3 ISOlat1',                                    [u'Ã', 'A', 'tilde']],
        ['Auml',    196,  'latin capital letter A with diaeresis, U+00C4 ISOlat1',                                [u'Ä', 'A', 'diaeresis']],
        ['Aring',   197,  'latin capital letter A with ring above = latin capital letter A ring, U+00C5 ISOlat1', [u'Å', 'A', 'ring']],
        ['AElig',   198,  'latin capital letter AE = latin capital ligature AE, U+00C6 ISOlat1',                  [u'Æ', 'AE']],
        ['Ccedil',  199,  'latin capital letter C with cedilla, U+00C7 ISOlat1',                                  [u'Ç', 'C', 'cedilla']],
        ['Egrave',  200,  'latin capital letter E with grave, U+00C8 ISOlat1',                                    [u'È', 'E', 'grave']],
        ['Eacute',  201,  'latin capital letter E with acute, U+00C9 ISOlat1',                                    [u'É', 'E', 'acute']],
        ['Ecirc',   202,  'latin capital letter E with circumflex, U+00CA ISOlat1',                               [u'Ê', 'E', 'circumflex']],
        ['Euml',    203,  'latin capital letter E with diaeresis, U+00CB ISOlat1',                                [u'Ë', 'E', 'diaeresis']],
        ['Igrave',  204,  'latin capital letter I with grave, U+00CC ISOlat1',                                    [u'Ì', 'I', 'grave', 'L']],
        ['Iacute',  205,  'latin capital letter I with acute, U+00CD ISOlat1',                                    [u'Í', 'I', 'acute', 'L']],
        ['Icirc',   206,  'latin capital letter I with circumflex, U+00CE ISOlat1',                               [u'Î', 'I', 'circumflex', 'L']],
        ['Iuml',    207,  'latin capital letter I with diaeresis, U+00CF ISOlat1',                                [u'Ï', 'I', 'diaeresis', 'L']],
        ['ETH',     208,  'latin capital letter ETH, U+00D0 ISOlat1',                                             [u'Ð', 'ETH', 'D']],
        ['Ntilde',  209,  'latin capital letter N with tilde, U+00D1 ISOlat1',                                    [u'Ñ', 'N', 'tilde']],
        ['Ograve',  210,  'latin capital letter O with grave, U+00D2 ISOlat1',                                    [u'Ò', 'O', 'grave']],
        ['Oacute',  211,  'latin capital letter O with acute, U+00D3 ISOlat1',                                    [u'Ó', 'O', 'acute']],
        ['Ocirc',   212,  'latin capital letter O with circumflex, U+00D4 ISOlat1',                               [u'Ô', 'O', 'circumflex']],
        ['Otilde',  213,  'latin capital letter O with tilde, U+00D5 ISOlat1',                                    [u'Õ', 'O', 'tilde']],
        ['Ouml',    214,  'latin capital letter O with diaeresis, U+00D6 ISOlat1',                                [u'Ö', 'O', 'diaeresis']],
        ['times',   215,  'multiplication sign, U+00D7 ISOnum',                                                   [u'×', 'multiplication', 'x', 'times']],
        ['Oslash',  216,  'latin capital letter O with stroke = latin capital letter O slash, U+00D8 ISOlat1',    [u'Ø', 'O', 'stroke', 'slash']],
        ['Ugrave',  217,  'latin capital letter U with grave, U+00D9 ISOlat1',                                    [u'Ù', 'U', 'grave']],
        ['Uacute',  218,  'latin capital letter U with acute, U+00DA ISOlat1',                                    [u'Ú', 'U', 'acute']],
        ['Ucirc',   219,  'latin capital letter U with circumflex, U+00DB ISOlat1',                               [u'Û', 'U', 'circumflex']],
        ['Uuml',    220,  'latin capital letter U with diaeresis, U+00DC ISOlat1',                                [u'Ü', 'U', 'diaeresis']],
        ['Yacute',  221,  'latin capital letter Y with acute, U+00DD ISOlat1',                                    [u'Ý', 'Y', 'acute']],
        ['THORN',   222,  'latin capital letter THORN, U+00DE ISOlat1',                                           [u'Þ', 'THORN', 'P']],
        ['szlig',   223,  'latin small letter sharp s = ess-zed, U+00DF ISOlat1',                                 [u'ß', 'b', 'beta', 'ess-zed', 's']],
        ['agrave',  224,  'latin small letter a with grave = latin small letter a grave, U+00E0 ISOlat1',         [u'à', 'a', 'grave']],
        ['aacute',  225,  'latin small letter a with acute, U+00E1 ISOlat1',                                      [u'á', 'a', 'acute']],
        ['acirc',   226,  'latin small letter a with circumflex, U+00E2 ISOlat1',                                 [u'â', 'a', 'circumflex']],
        ['atilde',  227,  'latin small letter a with tilde, U+00E3 ISOlat1',                                      [u'ã', 'a', 'tilde']],
        ['auml',    228,  'latin small letter a with diaeresis, U+00E4 ISOlat1',                                  [u'ä', 'a', 'diaeresis']],
        ['aring',   229,  'latin small letter a with ring above = latin small letter a ring, U+00E5 ISOlat1',     [u'å', 'a', 'ring']],
        ['aelig',   230,  'latin small letter ae = latin small ligature ae, U+00E6 ISOlat1',                      [u'æ', 'ae']],
        ['ccedil',  231,  'latin small letter c with cedilla, U+00E7 ISOlat1',                                    [u'ç', 'c', 'cedilla']],
        ['egrave',  232,  'latin small letter e with grave, U+00E8 ISOlat1',                                      [u'è', 'e', 'grave']],
        ['eacute',  233,  'latin small letter e with acute, U+00E9 ISOlat1',                                      [u'é', 'e', 'acute']],
        ['ecirc',   234,  'latin small letter e with circumflex, U+00EA ISOlat1',                                 [u'ê', 'e', 'circumflex']],
        ['euml',    235,  'latin small letter e with diaeresis, U+00EB ISOlat1',                                  [u'ë', 'e', 'diaeresis']],
        ['igrave',  236,  'latin small letter i with grave, U+00EC ISOlat1',                                      [u'ì', 'i', 'grave', 'L']],
        ['iacute',  237,  'latin small letter i with acute, U+00ED ISOlat1',                                      [u'í', 'i', 'acute', 'L']],
        ['icirc',   238,  'latin small letter i with circumflex, U+00EE ISOlat1',                                 [u'î', 'i', 'circumflex', 'L']],
        ['iuml',    239,  'latin small letter i with diaeresis, U+00EF ISOlat1',                                  [u'ï', 'i', 'diaeresis', 'L']],
        ['eth',     240,  'latin small letter eth, U+00F0 ISOlat1',                                               [u'ð', 'eth', 'o']],
        ['ntilde',  241,  'latin small letter n with tilde, U+00F1 ISOlat1',                                      [u'ñ', 'n', 'tilde']],
        ['ograve',  242,  'latin small letter o with grave, U+00F2 ISOlat1',                                      [u'ò', 'o', 'grave']],
        ['oacute',  243,  'latin small letter o with acute, U+00F3 ISOlat1',                                      [u'ó', 'o', 'acute']],
        ['ocirc',   244,  'latin small letter o with circumflex, U+00F4 ISOlat1',                                 [u'ô', 'o', 'circumflex']],
        ['otilde',  245,  'latin small letter o with tilde, U+00F5 ISOlat1',                                      [u'õ', 'o', 'tilde']],
        ['ouml',    246,  'latin small letter o with diaeresis, U+00F6 ISOlat1',                                  [u'ö', 'o', 'diaeresis']],
        ['divide',  247,  'division sign, U+00F7 ISOnum',                                                         [u'÷', 'division', '/', 'div']],
        ['oslash',  248,  'latin small letter o with stroke, = latin small letter o slash, U+00F8 ISOlat1',       [u'ø', 'o', 'stroke', 'slash']],
        ['ugrave',  249,  'latin small letter u with grave, U+00F9 ISOlat1',                                      [u'ù', 'u', 'grave']],
        ['uacute',  250,  'latin small letter u with acute, U+00FA ISOlat1',                                      [u'ú', 'u', 'acute']],
        ['ucirc',   251,  'latin small letter u with circumflex, U+00FB ISOlat1',                                 [u'û', 'u', 'circumflex']],
        ['uuml',    252,  'latin small letter u with diaeresis, U+00FC ISOlat1',                                  [u'ü', 'u', 'diaeresis']],
        ['yacute',  253,  'latin small letter y with acute, U+00FD ISOlat1',                                      [u'ý', 'y', 'acute']],
        ['thorn',   254,  'latin small letter thorn, U+00FE ISOlat1',                                             [u'þ', 'p', 'thorn']],
        ['yuml',    255,  'latin small letter y with diaeresis, U+00FF ISOlat1',                                  [u'ÿ', 'y', 'diaeresis']],
        ['fnof',    402,  'latin small f with hook = function = florin, U+0192 ISOtech',                          [u'ƒ', 'f', 'hook', 'function', 'florin']],
        ['Alpha',   913,  'greek capital letter alpha, U+0391',                                                   [u'Α', 'a', 'alpha']],
        ['Beta',    914,  'greek capital letter beta, U+0392',                                                    [u'Β', 'B', 'beta']],
        ['Gamma',   915,  'greek capital letter gamma, U+0393 ISOgrk3',                                           [u'Γ', 'gamma', 'L']],
        ['Delta',   916,  'greek capital letter delta, U+0394 ISOgrk3',                                           [u'Δ', 'delta', 'triangle']],
        ['Epsilon', 917,  'greek capital letter epsilon, U+0395',                                                 [u'Ε', 'e', 'epsilon']],
        ['Zeta',    918,  'greek capital letter zeta, U+0396',                                                    [u'Ζ', 'z', 'zeta']],
        ['Eta',     919,  'greek capital letter eta, U+0397',                                                     [u'Η', 'h', 'eta']],
        ['Theta',   920,  'greek capital letter theta, U+0398 ISOgrk3',                                           [u'Θ', 'theta', 'o']],
        ['Iota',    921,  'greek capital letter iota, U+0399',                                                    [u'Ι', 'i', 'iota']],
        ['Kappa',   922,  'greek capital letter kappa, U+039A',                                                   [u'Κ', 'k', 'kappa']],
        ['Lambda',  923,  'greek capital letter lambda, U+039B ISOgrk3',                                          [u'Λ', 'lambda', 'triangle']],
        ['Mu',      924,  'greek capital letter mu, U+039C',                                                      [u'Μ', 'm', 'mu']],
        ['Nu',      925,  'greek capital letter nu, U+039D',                                                      [u'Ν', 'n', 'nu']],
        ['Xi',      926,  'greek capital letter xi, U+039E ISOgrk3',                                              [u'Ξ', 'xi', 'e']],
        ['Omicron', 927,  'greek capital letter omicron, U+039F',                                                 [u'Ο', 'o', 'omicron']],
        ['Pi',      928,  'greek capital letter pi, U+03A0 ISOgrk3',                                              [u'Π', 'pi']],
        ['Rho',     929,  'greek capital letter rho, U+03A1',                                                     [u'Ρ', 'p', 'rho']],
        ['Sigma',   931,  'greek capital letter sigma, U+03A3 ISOgrk3',                                           [u'Σ', 'sigma', 'e']],
        ['Tau',     932,  'greek capital letter tau, U+03A4',                                                     [u'Τ', 't', 'tau']],
        ['Upsilon', 933,  'greek capital letter upsilon, U+03A5 ISOgrk3',                                         [u'Υ', 'upsilon', 'y']],
        ['Phi',     934,  'greek capital letter phi, U+03A6 ISOgrk3',                                             [u'Φ', 'o', 'phi']],
        ['Chi',     935,  'greek capital letter chi, U+03A7',                                                     [u'Χ', 'x', 'chi']],
        ['Psi',     936,  'greek capital letter psi, U+03A8 ISOgrk3',                                             [u'Ψ', 'y', 'psi']],
        ['Omega',   937,  'greek capital letter omega, U+03A9 ISOgrk3',                                           [u'Ω', 'omega', 'o']],
        ['alpha',   945,  'greek small letter alpha, U+03B1 ISOgrk3',                                             [u'α', 'alpha', 'a']],
        ['beta',    946,  'greek small letter beta, U+03B2 ISOgrk3',                                              [u'β', 'b', 'beta']],
        ['gamma',   947,  'greek small letter gamma, U+03B3 ISOgrk3',                                             [u'γ', 'y', 'gamma']],
        ['delta',   948,  'greek small letter delta, U+03B4 ISOgrk3',                                             [u'δ', 'd', 'delta', 'o']],
        ['epsilon', 949,  'greek small letter epsilon, U+03B5 ISOgrk3',                                           [u'ε', 'e', 'epsilon']],
        ['zeta',    950,  'greek small letter zeta, U+03B6 ISOgrk3',                                              [u'ζ', 'z', 'zeta']],
        ['eta',     951,  'greek small letter eta, U+03B7 ISOgrk3',                                               [u'η', 'n', 'eta']],
        ['theta',   952,  'greek small letter theta, U+03B8 ISOgrk3',                                             [u'θ', 'o', 'theta']],
        ['iota',    953,  'greek small letter iota, U+03B9 ISOgrk3',                                              [u'ι', 'i', 'l', 'iota']],
        ['kappa',   954,  'greek small letter kappa, U+03BA ISOgrk3',                                             [u'κ', 'k', 'kappa']],
        ['lambda',  955,  'greek small letter lambda, U+03BB ISOgrk3',                                            [u'λ', 'n', 'lambda', 'y']],
        ['mu',      956,  'greek small letter mu, U+03BC ISOgrk3',                                                [u'μ', 'u', 'mu']],
        ['nu',      957,  'greek small letter nu, U+03BD ISOgrk3',                                                [u'ν', 'nu', 'v']],
        ['xi',      958,  'greek small letter xi, U+03BE ISOgrk3',                                                [u'ξ', 'e', 'xi']],
        ['omicron', 959,  'greek small letter omicron, U+03BF NEW',                                               [u'ο', 'o', 'omicron']],
        ['pi',      960,  'greek small letter pi, U+03C0 ISOgrk3',                                                [u'π', 'pi']],
        ['rho',     961,  'greek small letter rho, U+03C1 ISOgrk3',                                               [u'ρ', 'p', 'o', 'rho']],
        ['sigmaf',  962,  'greek small letter final sigma, U+03C2 ISOgrk3',                                       [u'ς', 'c', 'sigma', 'final']],
        ['sigma',   963,  'greek small letter sigma, U+03C3 ISOgrk3',                                             [u'σ', 'o', 'sigma']],
        ['tau',     964,  'greek small letter tau, U+03C4 ISOgrk3',                                               [u'τ', 't', 'tau']],
        ['upsilon', 965,  'greek small letter upsilon, U+03C5 ISOgrk3',                                           [u'υ', 'u', 'upsilon']],
        ['phi',     966,  'greek small letter phi, U+03C6 ISOgrk3',                                               [u'φ', 'y', 'phi']],
        ['chi',     967,  'greek small letter chi, U+03C7 ISOgrk3',                                               [u'χ', 'x', 'chi']],
        ['psi',     968,  'greek small letter psi, U+03C8 ISOgrk3',                                               [u'ψ', 'y', 'psi']],
        ['omega',   969,  'greek small letter omega, U+03C9 ISOgrk3',                                             [u'ω', 'w', 'omega']],
        ['thetasym',977,  'greek small letter theta symbol, U+03D1 NEW',                                          [u'ϑ', '0', 'theta']],
        ['upsih',   978,  'greek upsilon with hook symbol, U+03D2 NEW',                                           [u'ϒ', 'y', 'hook', 'upsilon']],
        ['piv',     982,  'greek pi symbol, U+03D6 ISOgrk3',                                                      [u'ϖ', 'pi']],
        ['bull',    8226, 'bullet = black small circle, U+2022 ISOpub ',                                          [u'•', '*', 'bullet']],
        ['hellip',  8230, 'horizontal ellipsis = three dot leader, U+2026 ISOpub ',                               [u'…', '...']],
        ['prime',   8242, 'prime = minutes = feet, U+2032 ISOtech',                                               [u'′', "'", '`', 'prime']],
        ['Prime',   8243, 'double prime = seconds = inches, U+2033 ISOtech',                                      [u'″', '"', 'double', "''"]],
        ['oline',   8254, 'overline = spacing overscore, U+203E NEW',                                             [u'‾', 'overline', 'overscore', '_']],
        ['frasl',   8260, 'fraction slash, U+2044 NEW',                                                           [u'⁄', '/', 'fraction', 'slash']],
        ['weierp',  8472, 'script capital P = power set = Weierstrass p, U+2118 ISOamso',                         [u'℘', 'P', 'power']],
        ['image',   8465, 'blackletter capital I = imaginary part, U+2111 ISOamso',                               [u'ℑ', 'blackletter', 'I', 'imaginary']],
        ['real',    8476, 'blackletter capital R = real part symbol, U+211C ISOamso',                             [u'ℜ', 'R', 'blackletter', 'real', 'part']],
        ['trade',   8482, 'trade mark sign, U+2122 ISOnum',                                                       [u'™', 'trade', 'mark', 'tm']],
        ['alefsym', 8501, 'alef symbol = first transfinite cardinal, U+2135 NEW',                                 [u'ℵ', 'alef', 'transfinite', 'n']],
        ['larr',    8592, 'leftwards arrow, U+21',                                                                [u'←', '<-', '<', 'leftwards', 'arrow']],
        ['rarr',    8594, 'rightwards arrow, U+2192 ISOnum',                                                      [u'→', '->', '>', 'rightwards', 'arrow']],
        ['darr',    8595, 'downwards arrow, U+2193 ISOnum',                                                       [u'↓', 'downwards', 'arrow']],
        ['harr',    8596, 'left right arrow, U+2194 ISOamsa',                                                     [u'↔', '<->',  'right', '<>', 'left', 'arrow']],
        ['crarr',   8629, 'downwards arrow with corner leftwards = carriage return, U+21B5 NEW',                  [u'↵', 'downwards', 'arrow', 'leftwards', 'carriage', 'return', 'enter']],
        ['lArr',    8656, 'leftwards double arrow, U+21D0 ISOtech.',                                              [u'⇐', 'double', 'arrow', '<', '<-', '<=']],
        ['uarr',    8593, 'upwards arrow, U+2191 ISOnum',                                                         [u'upwards', 'arrow']],
        ['uArr',    8657, 'upwards double arrow, U+21D1 ISOamsa',                                                 [u'⇑', 'upwards', 'double', 'arrow']],
        ['rArr',    8658, 'rightwards double arrow, U+21D2 ISOtech.',                                             [u'⇒', '>', '->', 'rightwards', 'double', '=>', 'arrow']],
        ['dArr',    8659, 'downwards double arrow, U+21D3 ISOamsa',                                               [u'⇓', 'downwards', 'double', 'arrow']],
        ['hArr',    8660, 'left right double arrow, U+21D4 ISOamsa',                                              [u'⇔', '<>', '<=>', '<->', 'left', 'right', 'double', 'arrow']],
        ['forall',  8704, 'for all, U+2200 ISOtech',                                                              [u'∀', 'all', 'A']],
        ['part',    8706, 'partial differential, U+2202 ISOtech ',                                                [u'∂', 'partial', 'differential', 'd']],
        ['exist',   8707, 'there exists, U+2203 ISOtech',                                                         [u'∃', 'e', 'exists']],
        ['empty',   8709, 'empty set = null set = diameter, U+2205 ISOamso',                                      [u'∅', 'o', 'empty', 'set', 'null', 'diameter']],
        ['nabla',   8711, 'nabla = backward difference, U+2207 ISOtech',                                          [u'∇', 'nabla', 'difference', 'triangle']],
        ['isin',    8712, 'element of, U+2208 ISOtech',                                                           [u'∈', 'element', 'e']],
        ['notin',   8713, 'not an element of, U+2209 ISOtech',                                                    [u'∉', 'e', 'not', 'element']],
        ['ni',      8715, 'contains as member, U+220B ISOtech',                                                   [u'∋', 'contains', 'member', 'e']],
        ['prod',    8719, 'n-ary product = product sign, U+220F ISOamsb',                                         [u'∏', 'n-ary', 'product', 'n']],
        ['sum',     8721, 'n-ary sumation, U+2211 ISOamsb',                                                       [u'∑', 'e', 'n-ary', 'sumation']],
        ['minus',   8722, 'minus sign, U+2212 ISOtech',                                                           [u'−', '-', 'minus']],
        ['lowast',  8727, 'asterisk operator, U+2217 ISOtech',                                                    [u'∗', 'asterisk', '*', 'bullet']],
        ['radic',   8730, 'square root = radical sign, U+221A ISOtech',                                           [u'√', 'square', 'root', 'y', '^']],
        ['prop',    8733, 'proportional to, U+221D ISOtech',                                                      [u'∝', 'proportional']],
        ['infin',   8734, 'infinity, U+221E ISOtech',                                                             [u'∞', 'infinity']],
        ['ang',     8736, 'angle, U+2220 ISOamso',                                                                [u'∠', 'angle', '<']],
        ['and',     8743, 'logical and = wedge, U+2227 ISOtech',                                                  [u'∧', 'logical', 'and', 'wedge', '^']],
        ['or',      8744, 'logical or = vee, U+2228 ISOtech',                                                     [u'∨', 'logical', 'or', 'vee']],
        ['cap',     8745, 'intersection = cap, U+2229 ISOtech',                                                   [u'∩', 'intersection', 'cap']],
        ['cup',     8746, 'union = cup, U+222A ISOtech',                                                          [u'∪', 'union', 'cup']],
        ['int',     8747, 'integral, U+222B ISOtech',                                                             [u'∫', 'integral', 'f']],
        ['there4',  8756, 'therefore, U+2234 ISOtech',                                                            [u'∴', 'therefore', '...']],
        ['sim',     8764, 'tilde operator = varies with = similar to, U+223C ISOtech',                            [u'∼', 'tilde', '~', 'similar']],
        ['cong',    8773, 'approximately equal to, U+2245 ISOtech',                                               [u'≅', 'approximately', 'equal', '=', '~']],
        ['asymp',   8776, 'almost equal to = asymptotic to, U+2248 ISOamsr',                                      [u'≈', 'almost', '~', '~~', '=', 'equal']],
        ['ne',      8800, 'not equal to, U+2260 ISOtech',                                                         [u'≠', 'not', 'equal', '=']],
        ['equiv',   8801, 'identical to, U+2261 ISOtech',                                                         [u'≡', 'identical', '=']],
        ['le',      8804, 'less-than or equal to, U+2264 ISOtech',                                                [u'≤', 'less-than', 'equal', '<=', '=<', '<', '=']],
        ['ge',      8805, 'greater-than or equal to, U+2265 ISOtech',                                             [u'≥', 'greater-than', 'equal', '>=', '=>', '=', '>']],
        ['sub',     8834, 'subset of, U+2282 ISOtech',                                                            [u'⊂', 'subset', 'c']],
        ['sup',     8835, 'superset of, U+2283 ISOtech',                                                          [u'⊃', 'superset', 'c']],
        ['nsub',    8836, 'not a subset of, U+2284 ISOamsn',                                                      [u'⊄', 'c', 'not', 'subset']],
        ['sube',    8838, 'subset of or equal to, U+2286 ISOtech',                                                [u'⊆', 'subset', 'equal', 'c', '=']],
        ['supe',    8839, 'superset of or equal to, U+2287 ISOtech',                                              [u'⊇', 'c', 'superset', 'equal', '=']],
        ['oplus',   8853, 'circled plus = direct sum, U+2295 ISOamsb',                                            [u'⊕', 'circled', 'plus', '+', 'O', '0']],
        ['otimes',  8855, 'circled times = vector product, U+2297 ISOamsb',                                       [u'⊗', 'circled', 'times', 'vector', 'x', '*', 'o', '0']],
        ['perp',    8869, 'up tack = orthogonal to = perpendicular, U+22A5 ISOtech',                              [u'⊥', 'up', '|', 'orthogonal', 'perpendicular']],
        ['sdot',    8901, 'dot operator, U+22C5 ISOamsb',                                                         [u'⋅', '.', 'dot', '*', 'bullet']],
        ['lceil',   8968, 'left ceiling = apl upstile, U+2308 ISOamsc ',                                          [u'⌈', '[', 'ceiling']],
        ['rceil',   8969, 'right ceiling, U+2309 ISOamsc ',                                                       [u'⌉', ']', 'right']],
        ['lfloor',  8970, 'left floor = apl downstile, U+230A ISOamsc ',                                          [u'⌊', '[', 'floor']],
        ['rfloor',  8971, 'right floor, U+230B ISOamsc ',                                                         [u'⌋', ']', 'right', 'floor']],
        ['lang',    9001, 'left-pointing angle bracket = bra, U+2329 ISOtech',                                    [u'〈', '<', 'angle', 'bracket']],
        ['rang',    9002, 'right-pointing angle bracket = ket, U+232A ISOtech',                                   [u'〉', '>', 'angle', 'bracket']],
        ['loz',     9674, 'lozenge, U+25CA ISOpub',                                                               [u'◊', '<>', 'lozenge', 'diamond']],
        ['spades',  9824, 'black spade suit, U+2660 ISOpub',                                                      [u'♠', 'spade', 'card', 'cards']],
        ['clubs',   9827, 'black club suit = shamrock, U+2663 ISOpub',                                            [u'♣', 'club', 'shamrock', 'card', 'cards']],
        ['hearts',  9829, 'black heart suit = valentine, U+2665 ISOpub',                                          [u'♥', 'heart', 'valentine', 'card', 'cards']],
        ['diams',   9830, 'black diamond suit, U+2666 ISOpub',                                                    [u'♦', 'card', 'cards', 'diamond']],
        ['quot',    34,   'quotation mark = APL quote, U+0022 ISOnum',                                            [u"'", 'quotation']],
        ['amp',     38,   'ampersand, U+0026 ISOnum',                                                             [u'&', '&', 'and', 'ampersand']],
        ['lt',      60,   'less-than sign, U+003C ISOnum',                                                        [u'<', 'less-than', '<', 'left', 'arrow']],
        ['gt',      62,   'greater-than sign, U+003E ISOnum',                                                     [u'>', '>', 'greater-than']],
        ['OElig',   338,  'latin capital ligature OE, U+0152 ISOlat2',                                            [u'Œ', 'OE']],
        ['oelig',   339,  'latin small ligature oe, U+0153 ISOlat2',                                              [u'œ', 'oe']],
        ['Scaron',  352,  'latin capital letter S with caron, U+0160 ISOlat2',                                    [u'Š', 'S', 'caron']],
        ['scaron',  353,  'latin small letter s with caron, U+0161 ISOlat2',                                      [u'š', 's', 'caron']],
        ['Yuml',    376,  'latin capital letter Y with diaeresis, U+0178 ISOlat2',                                [u'Ÿ', 'Y', 'diaeresis']],
        ['circ',    710,  'modifier letter circumflex accent, U+02C6 ISOpub',                                     [u'ˆ', 'circumflex', 'accent', '^']],
        ['tilde',   732,  'small tilde, U+02DC ISOdia',                                                           [u'˜', 'tilde', '~']],
        ['ensp',    8194, 'en space, U+2002 ISOpub',                                                              [u'en', 'space']],
        ['emsp',    8195, 'em space, U+2003 ISOpub',                                                              [u'em', 'space']],
        ['thinsp',  8201, 'thin space, U+2009 ISOpub',                                                            [u'thin', 'space']],
        ['zwnj',    8204, 'zero width non-joiner, U+200C NEW RFC 2070',                                           [u'‌', ' ', 'zero', 'non-joiner']],
        ['zwj',     8205, 'zero width joiner, U+200D NEW RFC 2070',                                               [u'‍', ' ', 'zero']],
        ['ndash',   8211, 'en dash, U+2013 ISOpub',                                                               [u'–', 'n', 'en', 'dash', '-']],
        ['mdash',   8212, 'em dash, U+2014 ISOpub',                                                               [u'—', 'm', 'em', 'dash', '-']],
        ['lsquo',   8216, 'left single quotation mark, U+2018 ISOnum',                                            [u'‘', 'left', 'quotation', 'quote', '"']],
        ['rsquo',   8217, 'right single quotation mark, U+2019 ISOnum',                                           [u'’', "'", 'right', 'quotation', 'quote']],
        ['sbquo',   8218, 'single low-9 quotation mark, U+201A NEW',                                              [u'‚', ',', 'quotation', 'quote', 'low-9', 'low']],
        ['ldquo',   8220, 'left double quotation mark, U+201C ISOnum',                                            [u'“', '"', 'quotation', 'quote']],
        ['rdquo',   8221, 'right double quotation mark, U+201D ISOnum',                                           [u'”', '"', 'double', 'quotation', 'quote']],
        ['bdquo',   8222, 'double low-9 quotation mark, U+201E NEW',                                              [u'„', 'double', 'low-9', 'quotation', 'quote', '"']],
        ['dagger',  8224, 'dagger, U+2020 ISOpub',                                                                [u'†', '+', 'dagger']],
        ['Dagger',  8225, 'double dagger, U+2021 ISOpub',                                                         [u'‡', 'double', 'dagger', '++', '+']],
        ['permil',  8240, 'per mille sign, U+2030 ISOtech',                                                       [u'‰', 'per', 'mille', '%']],
        ['lsaquo',  8249, 'single left-pointing angle quotation mark, U+2039 ISO proposed',                       [u'‹', 'left-pointing', 'angle', '<']],
        ['rsaquo',  8250, 'single right-pointing angle quotation mark, U+203A ISO proposed',                      [u'›', 'right-pointing', 'angle', '>']],
        ['euro',    8364, 'euro sign, U+20AC NEW',                                                                [u'€', 'E', u'€', 'euro']]
    ]

    def __init__(self, query):
        self.query = query.replace('\\', '')

    def find(self):
        return [x for x in Entities.DATA if self.query in x[3] or self.query in x[0]]

    def results(self):
        results = self.find()
        rlen = len(results)
        if rlen == 0:
            return Entities.to_alfred([dict(arg='', title='No results', subtitle='Try a different keyword', icon='')])
        else:
            return Entities.to_alfred([dict(arg=x[0], title='&amp;%s; - &amp;#%s; - &amp;#x%s; - \\%s' % (x[0], x[1], hex(x[1]).replace('0x', ''), hex(x[1]).replace('0x', '').rjust(4, '0')), subtitle=x[2], icon='fonts/%s.png' % x[1]) for x in results])

    @staticmethod
    def to_alfred(items):
        result = '<?xml version="1.0"?>\n<items>\n'
        for item in items:
            result += '<item arg="%s" valid="yes"><title>%s</title><subtitle>%s</subtitle><icon>%s</icon></item>\n' % (item['arg'], item['title'], item['subtitle'], item['icon'])
        result += '</items>'
        return result

    @staticmethod
    def details(code):
        entity = [x for x in Entities.DATA if code == x[0]][0]
        subtitle = 'Press Enter to paste, or Cmd+Enter to copy'
        to_hex = hex(entity[1]).replace('0x', '')
        result = [
            dict(arg='&#%s;' % entity[1], title='&#%s; - character' % entity[1], subtitle=subtitle, icon='fonts/%s.png' % entity[1]),
            dict(arg='&amp;%s;' % entity[0], title='&amp;%s; - named entity' % entity[0], subtitle=subtitle, icon='fonts/%s.png' % entity[1]),
            dict(arg='&amp;#%s;' % entity[1], title='&amp;#%s; - decimal entity' % entity[1], subtitle=subtitle, icon='fonts/%s.png' % entity[1]),
            dict(arg='&amp;#x%s;' % to_hex, title='&amp;#x%s; - hexadecimal entity' % to_hex, subtitle=subtitle, icon='fonts/%s.png' % entity[1]),
            dict(arg='\\%s' % to_hex.rjust(4, '0'), title='\\%s - octal entity (for CSS content)' % to_hex.rjust(4, '0'), subtitle=subtitle, icon='fonts/%s.png' % entity[1])
        ]
        return Entities.to_alfred(result)
