Entities.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:11k
源码类别:

Email服务器

开发平台:

Delphi

  1. unit Entities;
  2. interface
  3. const
  4.   MaxEntNameLen = 8;
  5.   
  6. function GetEntValue(const Name: String): WideChar;
  7. function GetEntName(Code: Word): String;
  8. implementation
  9. uses
  10.   SysUtils, Classes;
  11. const
  12.   EntCount = 252;
  13. type
  14.   PEntity = ^TEntity;
  15.   TEntity = record
  16.     Name: String;
  17.     Code: Word
  18.   end;
  19.   TEntities = array[0..EntCount - 1] of TEntity;
  20. const
  21.   EntTab: TEntities = (
  22.     (Name: 'nbsp';     Code: 160),
  23.     (Name: 'iexcl';    Code: 161),
  24.     (Name: 'cent';     Code: 162),
  25.     (Name: 'pound';    Code: 163),
  26.     (Name: 'curren';   Code: 164),
  27.     (Name: 'yen';      Code: 165),
  28.     (Name: 'brvbar';   Code: 166),
  29.     (Name: 'sect';     Code: 167),
  30.     (Name: 'uml';      Code: 168),
  31.     (Name: 'copy';     Code: 169),
  32.     (Name: 'ordf';     Code: 170),
  33.     (Name: 'laquo';    Code: 171),
  34.     (Name: 'not';      Code: 172),
  35.     (Name: 'shy';      Code: 173),
  36.     (Name: 'reg';      Code: 174),
  37.     (Name: 'macr';     Code: 175),
  38.     (Name: 'deg';      Code: 176),
  39.     (Name: 'plusmn';   Code: 177),
  40.     (Name: 'sup2';     Code: 178),
  41.     (Name: 'sup3';     Code: 179),
  42.     (Name: 'acute';    Code: 180),
  43.     (Name: 'micro';    Code: 181),
  44.     (Name: 'para';     Code: 182),
  45.     (Name: 'middot';   Code: 183),
  46.     (Name: 'cedil';    Code: 184),
  47.     (Name: 'sup1';     Code: 185),
  48.     (Name: 'ordm';     Code: 186),
  49.     (Name: 'raquo';    Code: 187),
  50.     (Name: 'frac14';   Code: 188),
  51.     (Name: 'frac12';   Code: 189),
  52.     (Name: 'frac34';   Code: 190),
  53.     (Name: 'iquest';   Code: 191),
  54.     (Name: 'Agrave';   Code: 192),
  55.     (Name: 'Aacute';   Code: 193),
  56.     (Name: 'Acirc';    Code: 194),
  57.     (Name: 'Atilde';   Code: 195),
  58.     (Name: 'Auml';     Code: 196),
  59.     (Name: 'Aring';    Code: 197),
  60.     (Name: 'AElig';    Code: 198),
  61.     (Name: 'Ccedil';   Code: 199),
  62.     (Name: 'Egrave';   Code: 200),
  63.     (Name: 'Eacute';   Code: 201),
  64.     (Name: 'Ecirc';    Code: 202),
  65.     (Name: 'Euml';     Code: 203),
  66.     (Name: 'Igrave';   Code: 204),
  67.     (Name: 'Iacute';   Code: 205),
  68.     (Name: 'Icirc';    Code: 206),
  69.     (Name: 'Iuml';     Code: 207),
  70.     (Name: 'ETH';      Code: 208),
  71.     (Name: 'Ntilde';   Code: 209),
  72.     (Name: 'Ograve';   Code: 210),
  73.     (Name: 'Oacute';   Code: 211),
  74.     (Name: 'Ocirc';    Code: 212),
  75.     (Name: 'Otilde';   Code: 213),
  76.     (Name: 'Ouml';     Code: 214),
  77.     (Name: 'times';    Code: 215),
  78.     (Name: 'Oslash';   Code: 216),
  79.     (Name: 'Ugrave';   Code: 217),
  80.     (Name: 'Uacute';   Code: 218),
  81.     (Name: 'Ucirc';    Code: 219),
  82.     (Name: 'Uuml';     Code: 220),
  83.     (Name: 'Yacute';   Code: 221),
  84.     (Name: 'THORN';    Code: 222),
  85.     (Name: 'szlig';    Code: 223),
  86.     (Name: 'agrave';   Code: 224),
  87.     (Name: 'aacute';   Code: 225),
  88.     (Name: 'acirc';    Code: 226),
  89.     (Name: 'atilde';   Code: 227),
  90.     (Name: 'auml';     Code: 228),
  91.     (Name: 'aring';    Code: 229),
  92.     (Name: 'aelig';    Code: 230),
  93.     (Name: 'ccedil';   Code: 231),
  94.     (Name: 'egrave';   Code: 232),
  95.     (Name: 'eacute';   Code: 233),
  96.     (Name: 'ecirc';    Code: 234),
  97.     (Name: 'euml';     Code: 235),
  98.     (Name: 'igrave';   Code: 236),
  99.     (Name: 'iacute';   Code: 237),
  100.     (Name: 'icirc';    Code: 238),
  101.     (Name: 'iuml';     Code: 239),
  102.     (Name: 'eth';      Code: 240),
  103.     (Name: 'ntilde';   Code: 241),
  104.     (Name: 'ograve';   Code: 242),
  105.     (Name: 'oacute';   Code: 243),
  106.     (Name: 'ocirc';    Code: 244),
  107.     (Name: 'otilde';   Code: 245),
  108.     (Name: 'ouml';     Code: 246),
  109.     (Name: 'divide';   Code: 247),
  110.     (Name: 'oslash';   Code: 248),
  111.     (Name: 'ugrave';   Code: 249),
  112.     (Name: 'uacute';   Code: 250),
  113.     (Name: 'ucirc';    Code: 251),
  114.     (Name: 'uuml';     Code: 252),
  115.     (Name: 'yacute';   Code: 253),
  116.     (Name: 'thorn';    Code: 254),
  117.     (Name: 'yuml';     Code: 255),
  118.     (Name: 'fnof';     Code: 402),
  119.     (Name: 'Alpha';    Code: 913),
  120.     (Name: 'Beta';     Code: 914),
  121.     (Name: 'Gamma';    Code: 915),
  122.     (Name: 'Delta';    Code: 916),
  123.     (Name: 'Epsilon';  Code: 917),
  124.     (Name: 'Zeta';     Code: 918),
  125.     (Name: 'Eta';      Code: 919),
  126.     (Name: 'Theta';    Code: 920),
  127.     (Name: 'Iota';     Code: 921),
  128.     (Name: 'Kappa';    Code: 922),
  129.     (Name: 'Lambda';   Code: 923),
  130.     (Name: 'Mu';       Code: 924),
  131.     (Name: 'Nu';       Code: 925),
  132.     (Name: 'Xi';       Code: 926),
  133.     (Name: 'Omicron';  Code: 927),
  134.     (Name: 'Pi';       Code: 928),
  135.     (Name: 'Rho';      Code: 929),
  136.     (Name: 'Sigma';    Code: 931),
  137.     (Name: 'Tau';      Code: 932),
  138.     (Name: 'Upsilon';  Code: 933),
  139.     (Name: 'Phi';      Code: 934),
  140.     (Name: 'Chi';      Code: 935),
  141.     (Name: 'Psi';      Code: 936),
  142.     (Name: 'Omega';    Code: 937),
  143.     (Name: 'alpha';    Code: 945),
  144.     (Name: 'beta';     Code: 946),
  145.     (Name: 'gamma';    Code: 947),
  146.     (Name: 'delta';    Code: 948),
  147.     (Name: 'epsilon';  Code: 949),
  148.     (Name: 'zeta';     Code: 950),
  149.     (Name: 'eta';      Code: 951),
  150.     (Name: 'theta';    Code: 952),
  151.     (Name: 'iota';     Code: 953),
  152.     (Name: 'kappa';    Code: 954),
  153.     (Name: 'lambda';   Code: 955),
  154.     (Name: 'mu';       Code: 956),
  155.     (Name: 'nu';       Code: 957),
  156.     (Name: 'xi';       Code: 958),
  157.     (Name: 'omicron';  Code: 959),
  158.     (Name: 'pi';       Code: 960),
  159.     (Name: 'rho';      Code: 961),
  160.     (Name: 'sigmaf';   Code: 962),
  161.     (Name: 'sigma';    Code: 963),
  162.     (Name: 'tau';      Code: 964),
  163.     (Name: 'upsilon';  Code: 965),
  164.     (Name: 'phi';      Code: 966),
  165.     (Name: 'chi';      Code: 967),
  166.     (Name: 'psi';      Code: 968),
  167.     (Name: 'omega';    Code: 969),
  168.     (Name: 'thetasym'; Code: 977),
  169.     (Name: 'upsih';    Code: 978),
  170.     (Name: 'piv';      Code: 982),
  171.     (Name: 'bull';     Code: 8226),
  172.     (Name: 'hellip';   Code: 8230),
  173.     (Name: 'prime';    Code: 8242),
  174.     (Name: 'Prime';    Code: 8243),
  175.     (Name: 'oline';    Code: 8254),
  176.     (Name: 'frasl';    Code: 8260),
  177.     (Name: 'weierp';   Code: 8472),
  178.     (Name: 'image';    Code: 8465),
  179.     (Name: 'real';     Code: 8476),
  180.     (Name: 'trade';    Code: 8482),
  181.     (Name: 'alefsym';  Code: 8501),
  182.     (Name: 'larr';     Code: 8592),
  183.     (Name: 'uarr';     Code: 8593),
  184.     (Name: 'rarr';     Code: 8594),
  185.     (Name: 'darr';     Code: 8595),
  186.     (Name: 'harr';     Code: 8596),
  187.     (Name: 'crarr';    Code: 8629),
  188.     (Name: 'lArr';     Code: 8656),
  189.     (Name: 'uArr';     Code: 8657),
  190.     (Name: 'rArr';     Code: 8658),
  191.     (Name: 'dArr';     Code: 8659),
  192.     (Name: 'hArr';     Code: 8660),
  193.     (Name: 'forall';   Code: 8704),
  194.     (Name: 'part';     Code: 8706),
  195.     (Name: 'exist';    Code: 8707),
  196.     (Name: 'empty';    Code: 8709),
  197.     (Name: 'nabla';    Code: 8711),
  198.     (Name: 'isin';     Code: 8712),
  199.     (Name: 'notin';    Code: 8713),
  200.     (Name: 'ni';       Code: 8715),
  201.     (Name: 'prod';     Code: 8719),
  202.     (Name: 'sum';      Code: 8721),
  203.     (Name: 'minus';    Code: 8722),
  204.     (Name: 'lowast';   Code: 8727),
  205.     (Name: 'radic';    Code: 8730),
  206.     (Name: 'prop';     Code: 8733),
  207.     (Name: 'infin';    Code: 8734),
  208.     (Name: 'ang';      Code: 8736),
  209.     (Name: 'and';      Code: 8743),
  210.     (Name: 'or';       Code: 8744),
  211.     (Name: 'cap';      Code: 8745),
  212.     (Name: 'cup';      Code: 8746),
  213.     (Name: 'int';      Code: 8747),
  214.     (Name: 'there4';   Code: 8756),
  215.     (Name: 'sim';      Code: 8764),
  216.     (Name: 'cong';     Code: 8773),
  217.     (Name: 'asymp';    Code: 8776),
  218.     (Name: 'ne';       Code: 8800),
  219.     (Name: 'equiv';    Code: 8801),
  220.     (Name: 'le';       Code: 8804),
  221.     (Name: 'ge';       Code: 8805),
  222.     (Name: 'sub';      Code: 8834),
  223.     (Name: 'sup';      Code: 8835),
  224.     (Name: 'nsub';     Code: 8836),
  225.     (Name: 'sube';     Code: 8838),
  226.     (Name: 'supe';     Code: 8839),
  227.     (Name: 'oplus';    Code: 8853),
  228.     (Name: 'otimes';   Code: 8855),
  229.     (Name: 'perp';     Code: 8869),
  230.     (Name: 'sdot';     Code: 8901),
  231.     (Name: 'lceil';    Code: 8968),
  232.     (Name: 'rceil';    Code: 8969),
  233.     (Name: 'lfloor';   Code: 8970),
  234.     (Name: 'rfloor';   Code: 8971),
  235.     (Name: 'lang';     Code: 9001),
  236.     (Name: 'rang';     Code: 9002),
  237.     (Name: 'loz';      Code: 9674),
  238.     (Name: 'spades';   Code: 9824),
  239.     (Name: 'clubs';    Code: 9827),
  240.     (Name: 'hearts';   Code: 9829),
  241.     (Name: 'diams';    Code: 9830),
  242.     (Name: 'quot';     Code: 34),
  243.     (Name: 'amp';      Code: 38),
  244.     (Name: 'lt';       Code: 60),
  245.     (Name: 'gt';       Code: 62),
  246.     (Name: 'OElig';    Code: 338),
  247.     (Name: 'oelig';    Code: 339),
  248.     (Name: 'Scaron';   Code: 352),
  249.     (Name: 'scaron';   Code: 353),
  250.     (Name: 'Yuml';     Code: 376),
  251.     (Name: 'circ';     Code: 710),
  252.     (Name: 'tilde';    Code: 732),
  253.     (Name: 'ensp';     Code: 8194),
  254.     (Name: 'emsp';     Code: 8195),
  255.     (Name: 'thinsp';   Code: 8201),
  256.     (Name: 'zwnj';     Code: 8204),
  257.     (Name: 'zwj';      Code: 8205),
  258.     (Name: 'lrm';      Code: 8206),
  259.     (Name: 'rlm';      Code: 8207),
  260.     (Name: 'ndash';    Code: 8211),
  261.     (Name: 'mdash';    Code: 8212),
  262.     (Name: 'lsquo';    Code: 8216),
  263.     (Name: 'rsquo';    Code: 8217),
  264.     (Name: 'sbquo';    Code: 8218),
  265.     (Name: 'ldquo';    Code: 8220),
  266.     (Name: 'rdquo';    Code: 8221),
  267.     (Name: 'bdquo';    Code: 8222),
  268.     (Name: 'dagger';   Code: 8224),
  269.     (Name: 'Dagger';   Code: 8225),
  270.     (Name: 'permil';   Code: 8240),
  271.     (Name: 'lsaquo';   Code: 8249),
  272.     (Name: 'rsaquo';   Code: 8250),
  273.     (Name: 'euro';     Code: 8364)
  274.   );
  275. type
  276.   TEntList = class(TList)
  277.   private
  278.     function GetCode(const Name: String): Integer;
  279.   public
  280.     constructor Create;
  281.     property Code[const Name: String]: Integer read GetCode;
  282.   end;
  283. var
  284.   EntityList: TEntList;
  285. function EntCompare(Ent1, Ent2: Pointer): Integer;
  286. begin
  287.   Result := CompareStr(PEntity(Ent1)^.Name, PEntity(Ent2)^.Name)
  288. end;
  289. constructor TEntList.Create;
  290. var
  291.   I: Integer;
  292. begin
  293.   inherited Create;
  294.   Capacity := EntCount;
  295.   for I := 0 to EntCount - 1 do
  296.     Add(@EntTab[I]);
  297.   Sort(EntCompare)
  298. end;
  299. function TEntList.GetCode(const Name: String): Integer;
  300. var
  301.   I, L, U, Cmp: Integer;
  302. begin
  303.   L := 0;
  304.   U := Count - 1;
  305.   while L <= U do
  306.   begin
  307.     I := (L + U) div 2;
  308.     Cmp := CompareStr(Name, PEntity(Items[I])^.Name);
  309.     if Cmp = 0 then
  310.     begin
  311.       Result := PEntity(Items[I])^.Code;
  312.       Exit
  313.     end;
  314.     if Cmp < 0 then
  315.       U := I - 1
  316.     else
  317.       L := I + 1
  318.   end;
  319.   Result := 32
  320. end;
  321. function GetEntValue(const Name: String): WideChar;
  322. begin
  323.   Result := WideChar(EntityList.Code[Name])
  324. end;
  325. function GetEntName(Code: Word): String;
  326. var
  327.   I: Integer;
  328. begin
  329.   for I := 0 to EntCount - 1 do
  330.     if EntTab[I].Code = Code then
  331.     begin
  332.       Result := EntTab[I].Name;
  333.       Exit
  334.     end;
  335.   Result := ''
  336. end;
  337. initialization
  338.   EntityList := TEntList.Create
  339. finalization
  340.   EntityList.Free
  341.   
  342. end.