text:
using System;
using System.Collections;
using System.Text;

namespace Marius.Html.Hap
{
    /// <summary>
    /// A utility class to replace special characters by entities and vice-versa.
    /// Follows HTML 4.0 specification found at http://www.w3.org/TR/html4/sgml/entities.html
    /// </summary>
    public class HtmlEntity
    {
        #region Static Members

        private static readonly int _maxEntitySize;
        private static Hashtable _entityName;
        private static Hashtable _entityValue;

        /// <summary>
        /// A collection of entities indexed by name.
        /// </summary>
        public static Hashtable EntityName
        {
            get { return _entityName; }
        }

        /// <summary>
        /// A collection of entities indexed by value.
        /// </summary>
        public static Hashtable EntityValue
        {
            get { return _entityValue; }
        }

        #endregion

        #region Constructors

        static HtmlEntity()
        {
            _entityName = new Hashtable();
            _entityValue = new Hashtable();

            #region Entities Definition

            _entityValue.Add("nbsp", 160); // no-break space = non-breaking space, U+00A0 ISOnum
            _entityName.Add(160, "nbsp");
            _entityValue.Add("iexcl", 161); // inverted exclamation mark, U+00A1 ISOnum
            _entityName.Add(161, "iexcl");
            _entityValue.Add("cent", 162); // cent sign, U+00A2 ISOnum
            _entityName.Add(162, "cent");
            _entityValue.Add("pound", 163); // pound sign, U+00A3 ISOnum
            _entityName.Add(163, "pound");
            _entityValue.Add("curren", 164); // currency sign, U+00A4 ISOnum
            _entityName.Add(164, "curren");
            _entityValue.Add("yen", 165); // yen sign = yuan sign, U+00A5 ISOnum
            _entityName.Add(165, "yen");
            _entityValue.Add("brvbar", 166); // broken bar = broken vertical bar, U+00A6 ISOnum
            _entityName.Add(166, "brvbar");
            _entityValue.Add("sect", 167); // section sign, U+00A7 ISOnum
            _entityName.Add(167, "sect");
            _entityValue.Add("uml", 168); // diaeresis = spacing diaeresis, U+00A8 ISOdia
            _entityName.Add(168, "uml");
            _entityValue.Add("copy", 169); // copyright sign, U+00A9 ISOnum
            _entityName.Add(169, "copy");
            _entityValue.Add("ordf", 170); // feminine ordinal indicator, U+00AA ISOnum
            _entityName.Add(170, "ordf");
            _entityValue.Add("laquo", 171);
                // left-pointing double angle quotation mark = left pointing guillemet, U+00AB ISOnum
            _entityName.Add(171, "laquo");
            _entityValue.Add("not", 172); // not sign, U+00AC ISOnum
            _entityName.Add(172, "not");
            _entityValue.Add("shy", 173); // soft hyphen = discretionary hyphen, U+00AD ISOnum
            _entityName.Add(173, "shy");
            _entityValue.Add("reg", 174); // registered sign = registered trade mark sign, U+00AE ISOnum
            _entityName.Add(174, "reg");
            _entityValue.Add("macr", 175); // macron = spacing macron = overline = APL overbar, U+00AF ISOdia
            _entityName.Add(175, "macr");
            _entityValue.Add("deg", 176); // degree sign, U+00B0 ISOnum
            _entityName.Add(176, "deg");
            _entityValue.Add("plusmn", 177); // plus-minus sign = plus-or-minus sign, U+00B1 ISOnum
            _entityName.Add(177, "plusmn");
            _entityValue.Add("sup2", 178); // superscript two = superscript digit two = squared, U+00B2 ISOnum
            _entityName.Add(178, "sup2");
            _entityValue.Add("sup3", 179); // superscript three = superscript digit three = cubed, U+00B3 ISOnum
            _entityName.Add(179, "sup3");
            _entityValue.Add("acute", 180); // acute accent = spacing acute, U+00B4 ISOdia
            _entityName.Add(180, "acute");
            _entityValue.Add("micro", 181); // micro sign, U+00B5 ISOnum
            _entityName.Add(181, "micro");
            _entityValue.Add("para", 182); // pilcrow sign = paragraph sign, U+00B6 ISOnum
            _entityName.Add(182, "para");
            _entityValue.Add("middot", 183); // middle dot = Georgian comma = Greek middle dot, U+00B7 ISOnum
            _entityName.Add(183, "middot");
            _entityValue.Add("cedil", 184); // cedilla = spacing cedilla, U+00B8 ISOdia
            _entityName.Add(184, "cedil");
            _entityValue.Add("sup1", 185); // superscript one = superscript digit one, U+00B9 ISOnum
            _entityName.Add(185, "sup1");
            _entityValue.Add("ordm", 186); // masculine ordinal indicator, U+00BA ISOnum
            _entityName.Add(186, "ordm");
            _entityValue.Add("raquo", 187);
                // right-pointing double angle quotation mark = right pointing guillemet, U+00BB ISOnum
            _entityName.Add(187, "raquo");
            _entityValue.Add("frac14", 188); // vulgar fraction one quarter = fraction one quarter, U+00BC ISOnum
            _entityName.Add(188, "frac14");
            _entityValue.Add("frac12", 189); // vulgar fraction one half = fraction one half, U+00BD ISOnum
            _entityName.Add(189, "frac12");
            _entityValue.Add("frac34", 190); // vulgar fraction three quarters = fraction three quarters, U+00BE ISOnum
            _entityName.Add(190, "frac34");
            _entityValue.Add("iquest", 191); // inverted question mark = turned question mark, U+00BF ISOnum
            _entityName.Add(191, "iquest");
            _entityValue.Add("Agrave", 192);
                // latin capital letter A with grave = latin capital letter A grave, U+00C0 ISOlat1
            _entityName.Add(192, "Agrave");
            _entityValue.Add("Aacute", 193); // latin capital letter A with acute, U+00C1 ISOlat1
            _entityName.Add(193, "Aacute");
            _entityValue.Add("Acirc", 194); // latin capital letter A with circumflex, U+00C2 ISOlat1
            _entityName.Add(194, "Acirc");
            _entityValue.Add("Atilde", 195); // latin capital letter A with tilde, U+00C3 ISOlat1
            _entityName.Add(195, "Atilde");
            _entityValue.Add("Auml", 196); // latin capital letter A with diaeresis, U+00C4 ISOlat1
            _entityName.Add(196, "Auml");
            _entityValue.Add("Aring", 197);
                // latin capital letter A with ring above = latin capital letter A ring, U+00C5 ISOlat1
            _entityName.Add(197, "Aring");
            _entityValue.Add("AElig", 198); // latin capital letter AE = latin capital ligature AE, U+00C6 ISOlat1
            _entityName.Add(198, "AElig");
            _entityValue.Add("Ccedil", 199); // latin capital letter C with cedilla, U+00C7 ISOlat1
            _entityName.Add(199, "Ccedil");
            _entityValue.Add("Egrave", 200); // latin capital letter E with grave, U+00C8 ISOlat1
            _entityName.Add(200, "Egrave");
            _entityValue.Add("Eacute", 201); // latin capital letter E with acute, U+00C9 ISOlat1
            _entityName.Add(201, "Eacute");
            _entityValue.Add("Ecirc", 202); // latin capital letter E with circumflex, U+00CA ISOlat1
            _entityName.Add(202, "Ecirc");
            _entityValue.Add("Euml", 203); // latin capital letter E with diaeresis, U+00CB ISOlat1
            _entityName.Add(203, "Euml");
            _entityValue.Add("Igrave", 204); // latin capital letter I with grave, U+00CC ISOlat1
            _entityName.Add(204, "Igrave");
            _entityValue.Add("Iacute", 205); // latin capital letter I with acute, U+00CD ISOlat1
            _entityName.Add(205, "Iacute");
            _entityValue.Add("Icirc", 206); // latin capital letter I with circumflex, U+00CE ISOlat1
            _entityName.Add(206, "Icirc");
            _entityValue.Add("Iuml", 207); // latin capital letter I with diaeresis, U+00CF ISOlat1
            _entityName.Add(207, "Iuml");
            _entityValue.Add("ETH", 208); // latin capital letter ETH, U+00D0 ISOlat1
            _entityName.Add(208, "ETH");
            _entityValue.Add("Ntilde", 209); // latin capital letter N with tilde, U+00D1 ISOlat1
            _entityName.Add(209, "Ntilde");
            _entityValue.Add("Ograve", 210); // latin capital letter O with grave, U+00D2 ISOlat1
            _entityName.Add(210, "Ograve");
            _entityValue.Add("Oacute", 211); // latin capital letter O with acute, U+00D3 ISOlat1
            _entityName.Add(211, "Oacute");
            _entityValue.Add("Ocirc", 212); // latin capital letter O with circumflex, U+00D4 ISOlat1
            _entityName.Add(212, "Ocirc");
            _entityValue.Add("Otilde", 213); // latin capital letter O with tilde, U+00D5 ISOlat1
            _entityName.Add(213, "Otilde");
            _entityValue.Add("Ouml", 214); // latin capital letter O with diaeresis, U+00D6 ISOlat1
            _entityName.Add(214, "Ouml");
            _entityValue.Add("times", 215); // multiplication sign, U+00D7 ISOnum
            _entityName.Add(215, "times");
            _entityValue.Add("Oslash", 216);
                // latin capital letter O with stroke = latin capital letter O slash, U+00D8 ISOlat1
            _entityName.Add(216, "Oslash");
            _entityValue.Add("Ugrave", 217); // latin capital letter U with grave, U+00D9 ISOlat1
            _entityName.Add(217, "Ugrave");
            _entityValue.Add("Uacute", 218); // latin capital letter U with acute, U+00DA ISOlat1
            _entityName.Add(218, "Uacute");
            _entityValue.Add("Ucirc", 219); // latin capital letter U with circumflex, U+00DB ISOlat1
            _entityName.Add(219, "Ucirc");
            _entityValue.Add("Uuml", 220); // latin capital letter U with diaeresis, U+00DC ISOlat1
            _entityName.Add(220, "Uuml");
            _entityValue.Add("Yacute", 221); // latin capital letter Y with acute, U+00DD ISOlat1
            _entityName.Add(221, "Yacute");
            _entityValue.Add("THORN", 222); // latin capital letter THORN, U+00DE ISOlat1
            _entityName.Add(222, "THORN");
            _entityValue.Add("szlig", 223); // latin small letter sharp s = ess-zed, U+00DF ISOlat1
            _entityName.Add(223, "szlig");
            _entityValue.Add("agrave", 224);
                // latin small letter a with grave = latin small letter a grave, U+00E0 ISOlat1
            _entityName.Add(224, "agrave");
            _entityValue.Add("aacute", 225); // latin small letter a with acute, U+00E1 ISOlat1
            _entityName.Add(225, "aacute");
            _entityValue.Add("acirc", 226); // latin small letter a with circumflex, U+00E2 ISOlat1
            _entityName.Add(226, "acirc");
            _entityValue.Add("atilde", 227); // latin small letter a with tilde, U+00E3 ISOlat1
            _entityName.Add(227, "atilde");
            _entityValue.Add("auml", 228); // latin small letter a with diaeresis, U+00E4 ISOlat1
            _entityName.Add(228, "auml");
            _entityValue.Add("aring", 229);
                // latin small letter a with ring above = latin small letter a ring, U+00E5 ISOlat1
            _entityName.Add(229, "aring");
            _entityValue.Add("aelig", 230); // latin small letter ae = latin small ligature ae, U+00E6 ISOlat1
            _entityName.Add(230, "aelig");
            _entityValue.Add("ccedil", 231); // latin small letter c with cedilla, U+00E7 ISOlat1
            _entityName.Add(231, "ccedil");
            _entityValue.Add("egrave", 232); // latin small letter e with grave, U+00E8 ISOlat1
            _entityName.Add(232, "egrave");
            _entityValue.Add("eacute", 233); // latin small letter e with acute, U+00E9 ISOlat1
            _entityName.Add(233, "eacute");
            _entityValue.Add("ecirc", 234); // latin small letter e with circumflex, U+00EA ISOlat1
            _entityName.Add(234, "ecirc");
            _entityValue.Add("euml", 235); // latin small letter e with diaeresis, U+00EB ISOlat1
            _entityName.Add(235, "euml");
            _entityValue.Add("igrave", 236); // latin small letter i with grave, U+00EC ISOlat1
            _entityName.Add(236, "igrave");
            _entityValue.Add("iacute", 237); // latin small letter i with acute, U+00ED ISOlat1
            _entityName.Add(237, "iacute");
            _entityValue.Add("icirc", 238); // latin small letter i with circumflex, U+00EE ISOlat1
            _entityName.Add(238, "icirc");
            _entityValue.Add("iuml", 239); // latin small letter i with diaeresis, U+00EF ISOlat1
            _entityName.Add(239, "iuml");
            _entityValue.Add("eth", 240); // latin small letter eth, U+00F0 ISOlat1
            _entityName.Add(240, "eth");
            _entityValue.Add("ntilde", 241); // latin small letter n with tilde, U+00F1 ISOlat1
            _entityName.Add(241, "ntilde");
            _entityValue.Add("ograve", 242); // latin small letter o with grave, U+00F2 ISOlat1
            _entityName.Add(242, "ograve");
            _entityValue.Add("oacute", 243); // latin small letter o with acute, U+00F3 ISOlat1
            _entityName.Add(243, "oacute");
            _entityValue.Add("ocirc", 244); // latin small letter o with circumflex, U+00F4 ISOlat1
            _entityName.Add(244, "ocirc");
            _entityValue.Add("otilde", 245); // latin small letter o with tilde, U+00F5 ISOlat1
            _entityName.Add(245, "otilde");
            _entityValue.Add("ouml", 246); // latin small letter o with diaeresis, U+00F6 ISOlat1
            _entityName.Add(246, "ouml");
            _entityValue.Add("divide", 247); // division sign, U+00F7 ISOnum
            _entityName.Add(247, "divide");
            _entityValue.Add("oslash", 248);
                // latin small letter o with stroke, = latin small letter o slash, U+00F8 ISOlat1
            _entityName.Add(248, "oslash");
            _entityValue.Add("ugrave", 249); // latin small letter u with grave, U+00F9 ISOlat1
            _entityName.Add(249, "ugrave");
            _entityValue.Add("uacute", 250); // latin small letter u with acute, U+00FA ISOlat1
            _entityName.Add(250, "uacute");
            _entityValue.Add("ucirc", 251); // latin small letter u with circumflex, U+00FB ISOlat1
            _entityName.Add(251, "ucirc");
            _entityValue.Add("uuml", 252); // latin small letter u with diaeresis, U+00FC ISOlat1
            _entityName.Add(252, "uuml");
            _entityValue.Add("yacute", 253); // latin small letter y with acute, U+00FD ISOlat1
            _entityName.Add(253, "yacute");
            _entityValue.Add("thorn", 254); // latin small letter thorn, U+00FE ISOlat1
            _entityName.Add(254, "thorn");
            _entityValue.Add("yuml", 255); // latin small letter y with diaeresis, U+00FF ISOlat1
            _entityName.Add(255, "yuml");
            _entityValue.Add("fnof", 402); // latin small f with hook = function = florin, U+0192 ISOtech
            _entityName.Add(402, "fnof");
            _entityValue.Add("Alpha", 913); // greek capital letter alpha, U+0391
            _entityName.Add(913, "Alpha");
            _entityValue.Add("Beta", 914); // greek capital letter beta, U+0392
            _entityName.Add(914, "Beta");
            _entityValue.Add("Gamma", 915); // greek capital letter gamma, U+0393 ISOgrk3
            _entityName.Add(915, "Gamma");
            _entityValue.Add("Delta", 916); // greek capital letter delta, U+0394 ISOgrk3
            _entityName.Add(916, "Delta");
            _entityValue.Add("Epsilon", 917); // greek capital letter epsilon, U+0395
            _entityName.Add(917, "Epsilon");
            _entityValue.Add("Zeta", 918); // greek capital letter zeta, U+0396
            _entityName.Add(918, "Zeta");
            _entityValue.Add("Eta", 919); // greek capital letter eta, U+0397
            _entityName.Add(919, "Eta");
            _entityValue.Add("Theta", 920); // greek capital letter theta, U+0398 ISOgrk3
            _entityName.Add(920, "Theta");
            _entityValue.Add("Iota", 921); // greek capital letter iota, U+0399
            _entityName.Add(921, "Iota");
            _entityValue.Add("Kappa", 922); // greek capital letter kappa, U+039A
            _entityName.Add(922, "Kappa");
            _entityValue.Add("Lambda", 923); // greek capital letter lambda, U+039B ISOgrk3
            _entityName.Add(923, "Lambda");
            _entityValue.Add("Mu", 924); // greek capital letter mu, U+039C
            _entityName.Add(924, "Mu");
            _entityValue.Add("Nu", 925); // greek capital letter nu, U+039D
            _entityName.Add(925, "Nu");
            _entityValue.Add("Xi", 926); // greek capital letter xi, U+039E ISOgrk3
            _entityName.Add(926, "Xi");
            _entityValue.Add("Omicron", 927); // greek capital letter omicron, U+039F
            _entityName.Add(927, "Omicron");
            _entityValue.Add("Pi", 928); // greek capital letter pi, U+03A0 ISOgrk3
            _entityName.Add(928, "Pi");
            _entityValue.Add("Rho", 929); // greek capital letter rho, U+03A1
            _entityName.Add(929, "Rho");
            _entityValue.Add("Sigma", 931); // greek capital letter sigma, U+03A3 ISOgrk3
            _entityName.Add(931, "Sigma");
            _entityValue.Add("Tau", 932); // greek capital letter tau, U+03A4
            _entityName.Add(932, "Tau");
            _entityValue.Add("Upsilon", 933); // greek capital letter upsilon, U+03A5 ISOgrk3
            _entityName.Add(933, "Upsilon");
            _entityValue.Add("Phi", 934); // greek capital letter phi, U+03A6 ISOgrk3
            _entityName.Add(934, "Phi");
            _entityValue.Add("Chi", 935); // greek capital letter chi, U+03A7
            _entityName.Add(935, "Chi");
            _entityValue.Add("Psi", 936); // greek capital letter psi, U+03A8 ISOgrk3
            _entityName.Add(936, "Psi");
            _entityValue.Add("Omega", 937); // greek capital letter omega, U+03A9 ISOgrk3
            _entityName.Add(937, "Omega");
            _entityValue.Add("alpha", 945); // greek small letter alpha, U+03B1 ISOgrk3
            _entityName.Add(945, "alpha");
            _entityValue.Add("beta", 946); // greek small letter beta, U+03B2 ISOgrk3
            _entityName.Add(946, "beta");
            _entityValue.Add("gamma", 947); // greek small letter gamma, U+03B3 ISOgrk3
            _entityName.Add(947, "gamma");
            _entityValue.Add("delta", 948); // greek small letter delta, U+03B4 ISOgrk3
            _entityName.Add(948, "delta");
            _entityValue.Add("epsilon", 949); // greek small letter epsilon, U+03B5 ISOgrk3
            _entityName.Add(949, "epsilon");
            _entityValue.Add("zeta", 950); // greek small letter zeta, U+03B6 ISOgrk3
            _entityName.Add(950, "zeta");
            _entityValue.Add("eta", 951); // greek small letter eta, U+03B7 ISOgrk3
            _entityName.Add(951, "eta");
            _entityValue.Add("theta", 952); // greek small letter theta, U+03B8 ISOgrk3
            _entityName.Add(952, "theta");
            _entityValue.Add("iota", 953); // greek small letter iota, U+03B9 ISOgrk3
            _entityName.Add(953, "iota");
            _entityValue.Add("kappa", 954); // greek small letter kappa, U+03BA ISOgrk3
            _entityName.Add(954, "kappa");
            _entityValue.Add("lambda", 955); // greek small letter lambda, U+03BB ISOgrk3
            _entityName.Add(955, "lambda");
            _entityValue.Add("mu", 956); // greek small letter mu, U+03BC ISOgrk3
            _entityName.Add(956, "mu");
            _entityValue.Add("nu", 957); // greek small letter nu, U+03BD ISOgrk3
            _entityName.Add(957, "nu");
            _entityValue.Add("xi", 958); // greek small letter xi, U+03BE ISOgrk3
            _entityName.Add(958, "xi");
            _entityValue.Add("omicron", 959); // greek small letter omicron, U+03BF NEW
            _entityName.Add(959, "omicron");
            _entityValue.Add("pi", 960); // greek small letter pi, U+03C0 ISOgrk3
            _entityName.Add(960, "pi");
            _entityValue.Add("rho", 961); // greek small letter rho, U+03C1 ISOgrk3
            _entityName.Add(961, "rho");
            _entityValue.Add("sigmaf", 962); // greek small letter final sigma, U+03C2 ISOgrk3
            _entityName.Add(962, "sigmaf");
            _entityValue.Add("sigma", 963); // greek small letter sigma, U+03C3 ISOgrk3
            _entityName.Add(963, "sigma");
            _entityValue.Add("tau", 964); // greek small letter tau, U+03C4 ISOgrk3
            _entityName.Add(964, "tau");
            _entityValue.Add("upsilon", 965); // greek small letter upsilon, U+03C5 ISOgrk3
            _entityName.Add(965, "upsilon");
            _entityValue.Add("phi", 966); // greek small letter phi, U+03C6 ISOgrk3
            _entityName.Add(966, "phi");
            _entityValue.Add("chi", 967); // greek small letter chi, U+03C7 ISOgrk3
            _entityName.Add(967, "chi");
            _entityValue.Add("psi", 968); // greek small letter psi, U+03C8 ISOgrk3
            _entityName.Add(968, "psi");
            _entityValue.Add("omega", 969); // greek small letter omega, U+03C9 ISOgrk3
            _entityName.Add(969, "omega");
            _entityValue.Add("thetasym", 977); // greek small letter theta symbol, U+03D1 NEW
            _entityName.Add(977, "thetasym");
            _entityValue.Add("upsih", 978); // greek upsilon with hook symbol, U+03D2 NEW
            _entityName.Add(978, "upsih");
            _entityValue.Add("piv", 982); // greek pi symbol, U+03D6 ISOgrk3
            _entityName.Add(982, "piv");
            _entityValue.Add("bull", 8226); // bullet = black small circle, U+2022 ISOpub
            _entityName.Add(8226, "bull");
            _entityValue.Add("hellip", 8230); // horizontal ellipsis = three dot leader, U+2026 ISOpub
            _entityName.Add(8230, "hellip");
            _entityValue.Add("prime", 8242); // prime = minutes = feet, U+2032 ISOtech
            _entityName.Add(8242, "prime");
            _entityValue.Add("Prime", 8243); // double prime = seconds = inches, U+2033 ISOtech
            _entityName.Add(8243, "Prime");
            _entityValue.Add("oline", 8254); // overline = spacing overscore, U+203E NEW
            _entityName.Add(8254, "oline");
            _entityValue.Add("frasl", 8260); // fraction slash, U+2044 NEW
            _entityName.Add(8260, "frasl");
            _entityValue.Add("weierp", 8472); // script capital P = power set = Weierstrass p, U+2118 ISOamso
            _entityName.Add(8472, "weierp");
            _entityValue.Add("image", 8465); // blackletter capital I = imaginary part, U+2111 ISOamso
            _entityName.Add(8465, "image");
            _entityValue.Add("real", 8476); // blackletter capital R = real part symbol, U+211C ISOamso
            _entityName.Add(8476, "real");
            _entityValue.Add("trade", 8482); // trade mark sign, U+2122 ISOnum
            _entityName.Add(8482, "trade");
            _entityValue.Add("alefsym", 8501); // alef symbol = first transfinite cardinal, U+2135 NEW
            _entityName.Add(8501, "alefsym");
            _entityValue.Add("larr", 8592); // leftwards arrow, U+2190 ISOnum
            _entityName.Add(8592, "larr");
            _entityValue.Add("uarr", 8593); // upwards arrow, U+2191 ISOnum
            _entityName.Add(8593, "uarr");
            _entityValue.Add("rarr", 8594); // rightwards arrow, U+2192 ISOnum
            _entityName.Add(8594, "rarr");
            _entityValue.Add("darr", 8595); // downwards arrow, U+2193 ISOnum
            _entityName.Add(8595, "darr");
            _entityValue.Add("harr", 8596); // left right arrow, U+2194 ISOamsa
            _entityName.Add(8596, "harr");
            _entityValue.Add("crarr", 8629); // downwards arrow with corner leftwards = carriage return, U+21B5 NEW
            _entityName.Add(8629, "crarr");
            _entityValue.Add("lArr", 8656); // leftwards double arrow, U+21D0 ISOtech
            _entityName.Add(8656, "lArr");
            _entityValue.Add("uArr", 8657); // upwards double arrow, U+21D1 ISOamsa
            _entityName.Add(8657, "uArr");
            _entityValue.Add("rArr", 8658); // rightwards double arrow, U+21D2 ISOtech
            _entityName.Add(8658, "rArr");
            _entityValue.Add("dArr", 8659); // downwards double arrow, U+21D3 ISOamsa
            _entityName.Add(8659, "dArr");
            _entityValue.Add("hArr", 8660); // left right double arrow, U+21D4 ISOamsa
            _entityName.Add(8660, "hArr");
            _entityValue.Add("forall", 8704); // for all, U+2200 ISOtech
            _entityName.Add(8704, "forall");
            _entityValue.Add("part", 8706); // partial differential, U+2202 ISOtech
            _entityName.Add(8706, "part");
            _entityValue.Add("exist", 8707); // there exists, U+2203 ISOtech
            _entityName.Add(8707, "exist");
            _entityValue.Add("empty", 8709); // empty set = null set = diameter, U+2205 ISOamso
            _entityName.Add(8709, "empty");
            _entityValue.Add("nabla", 8711); // nabla = backward difference, U+2207 ISOtech
            _entityName.Add(8711, "nabla");
            _entityValue.Add("isin", 8712); // element of, U+2208 ISOtech
            _entityName.Add(8712, "isin");
            _entityValue.Add("notin", 8713); // not an element of, U+2209 ISOtech
            _entityName.Add(8713, "notin");
            _entityValue.Add("ni", 8715); // contains as member, U+220B ISOtech
            _entityName.Add(8715, "ni");
            _entityValue.Add("prod", 8719); // n-ary product = product sign, U+220F ISOamsb
            _entityName.Add(8719, "prod");
            _entityValue.Add("sum", 8721); // n-ary sumation, U+2211 ISOamsb
            _entityName.Add(8721, "sum");
            _entityValue.Add("minus", 8722); // minus sign, U+2212 ISOtech
            _entityName.Add(8722, "minus");
            _entityValue.Add("lowast", 8727); // asterisk operator, U+2217 ISOtech
            _entityName.Add(8727, "lowast");
            _entityValue.Add("radic", 8730); // square root = radical sign, U+221A ISOtech
            _entityName.Add(8730, "radic");
            _entityValue.Add("prop", 8733); // proportional to, U+221D ISOtech
            _entityName.Add(8733, "prop");
            _entityValue.Add("infin", 8734); // infinity, U+221E ISOtech
            _entityName.Add(8734, "infin");
            _entityValue.Add("ang", 8736); // angle, U+2220 ISOamso
            _entityName.Add(8736, "ang");
            _entityValue.Add("and", 8743); // logical and = wedge, U+2227 ISOtech
            _entityName.Add(8743, "and");
            _entityValue.Add("or", 8744); // logical or = vee, U+2228 ISOtech
            _entityName.Add(8744, "or");
            _entityValue.Add("cap", 8745); // intersection = cap, U+2229 ISOtech
            _entityName.Add(8745, "cap");
            _entityValue.Add("cup", 8746); // union = cup, U+222A ISOtech
            _entityName.Add(8746, "cup");
            _entityValue.Add("int", 8747); // integral, U+222B ISOtech
            _entityName.Add(8747, "int");
            _entityValue.Add("there4", 8756); // therefore, U+2234 ISOtech
            _entityName.Add(8756, "there4");
            _entityValue.Add("sim", 8764); // tilde operator = varies with = similar to, U+223C ISOtech
            _entityName.Add(8764, "sim");
            _entityValue.Add("cong", 8773); // approximately equal to, U+2245 ISOtech
            _entityName.Add(8773, "cong");
            _entityValue.Add("asymp", 8776); // almost equal to = asymptotic to, U+2248 ISOamsr
            _entityName.Add(8776, "asymp");
            _entityValue.Add("ne", 8800); // not equal to, U+2260 ISOtech
            _entityName.Add(8800, "ne");
            _entityValue.Add("equiv", 8801); // identical to, U+2261 ISOtech
            _entityName.Add(8801, "equiv");
            _entityValue.Add("le", 8804); // less-than or equal to, U+2264 ISOtech
            _entityName.Add(8804, "le");
            _entityValue.Add("ge", 8805); // greater-than or equal to, U+2265 ISOtech
            _entityName.Add(8805, "ge");
            _entityValue.Add("sub", 8834); // subset of, U+2282 ISOtech
            _entityName.Add(8834, "sub");
            _entityValue.Add("sup", 8835); // superset of, U+2283 ISOtech
            _entityName.Add(8835, "sup");
            _entityValue.Add("nsub", 8836); // not a subset of, U+2284 ISOamsn
            _entityName.Add(8836, "nsub");
            _entityValue.Add("sube", 8838); // subset of or equal to, U+2286 ISOtech
            _entityName.Add(8838, "sube");
            _entityValue.Add("supe", 8839); // superset of or equal to, U+2287 ISOtech
            _entityName.Add(8839, "supe");
            _entityValue.Add("oplus", 8853); // circled plus = direct sum, U+2295 ISOamsb
            _entityName.Add(8853, "oplus");
            _entityValue.Add("otimes", 8855); // circled times = vector product, U+2297 ISOamsb
            _entityName.Add(8855, "otimes");
            _entityValue.Add("perp", 8869); // up tack = orthogonal to = perpendicular, U+22A5 ISOtech
            _entityName.Add(8869, "perp");
            _entityValue.Add("sdot", 8901); // dot operator, U+22C5 ISOamsb
            _entityName.Add(8901, "sdot");
            _entityValue.Add("lceil", 8968); // left ceiling = apl upstile, U+2308 ISOamsc
            _entityName.Add(8968, "lceil");
            _entityValue.Add("rceil", 8969); // right ceiling, U+2309 ISOamsc
            _entityName.Add(8969, "rceil");
            _entityValue.Add("lfloor", 8970); // left floor = apl downstile, U+230A ISOamsc
            _entityName.Add(8970, "lfloor");
            _entityValue.Add("rfloor", 8971); // right floor, U+230B ISOamsc
            _entityName.Add(8971, "rfloor");
            _entityValue.Add("lang", 9001); // left-pointing angle bracket = bra, U+2329 ISOtech
            _entityName.Add(9001, "lang");
            _entityValue.Add("rang", 9002); // right-pointing angle bracket = ket, U+232A ISOtech
            _entityName.Add(9002, "rang");
            _entityValue.Add("loz", 9674); // lozenge, U+25CA ISOpub
            _entityName.Add(9674, "loz");
            _entityValue.Add("spades", 9824); // black spade suit, U+2660 ISOpub
            _entityName.Add(9824, "spades");
            _entityValue.Add("clubs", 9827); // black club suit = shamrock, U+2663 ISOpub
            _entityName.Add(9827, "clubs");
            _entityValue.Add("hearts", 9829); // black heart suit = valentine, U+2665 ISOpub
            _entityName.Add(9829, "hearts");
            _entityValue.Add("diams", 9830); // black diamond suit, U+2666 ISOpub
            _entityName.Add(9830, "diams");
            _entityValue.Add("quot", 34); // quotation mark = APL quote, U+0022 ISOnum
            _entityName.Add(34, "quot");
            _entityValue.Add("amp", 38); // ampersand, U+0026 ISOnum
            _entityName.Add(38, "amp");
            _entityValue.Add("lt", 60); // less-than sign, U+003C ISOnum
            _entityName.Add(60, "lt");
            _entityValue.Add("gt", 62); // greater-than sign, U+003E ISOnum
            _entityName.Add(62, "gt");
            _entityValue.Add("OElig", 338); // latin capital ligature OE, U+0152 ISOlat2
            _entityName.Add(338, "OElig");
            _entityValue.Add("oelig", 339); // latin small ligature oe, U+0153 ISOlat2
            _entityName.Add(339, "oelig");
            _entityValue.Add("Scaron", 352); // latin capital letter S with caron, U+0160 ISOlat2
            _entityName.Add(352, "Scaron");
            _entityValue.Add("scaron", 353); // latin small letter s with caron, U+0161 ISOlat2
            _entityName.Add(353, "scaron");
            _entityValue.Add("Yuml", 376); // latin capital letter Y with diaeresis, U+0178 ISOlat2
            _entityName.Add(376, "Yuml");
            _entityValue.Add("circ", 710); // modifier letter circumflex accent, U+02C6 ISOpub
            _entityName.Add(710, "circ");
            _entityValue.Add("tilde", 732); // small tilde, U+02DC ISOdia
            _entityName.Add(732, "tilde");
            _entityValue.Add("ensp", 8194); // en space, U+2002 ISOpub
            _entityName.Add(8194, "ensp");
            _entityValue.Add("emsp", 8195); // em space, U+2003 ISOpub
            _entityName.Add(8195, "emsp");
            _entityValue.Add("thinsp", 8201); // thin space, U+2009 ISOpub
            _entityName.Add(8201, "thinsp");
            _entityValue.Add("zwnj", 8204); // zero width non-joiner, U+200C NEW RFC 2070
            _entityName.Add(8204, "zwnj");
            _entityValue.Add("zwj", 8205); // zero width joiner, U+200D NEW RFC 2070
            _entityName.Add(8205, "zwj");
            _entityValue.Add("lrm", 8206); // left-to-right mark, U+200E NEW RFC 2070
            _entityName.Add(8206, "lrm");
            _entityValue.Add("rlm", 8207); // right-to-left mark, U+200F NEW RFC 2070
            _entityName.Add(8207, "rlm");
            _entityValue.Add("ndash", 8211); // en dash, U+2013 ISOpub
            _entityName.Add(8211, "ndash");
            _entityValue.Add("mdash", 8212); // em dash, U+2014 ISOpub
            _entityName.Add(8212, "mdash");
            _entityValue.Add("lsquo", 8216); // left single quotation mark, U+2018 ISOnum
            _entityName.Add(8216, "lsquo");
            _entityValue.Add("rsquo", 8217); // right single quotation mark, U+2019 ISOnum
            _entityName.Add(8217, "rsquo");
            _entityValue.Add("sbquo", 8218); // single low-9 quotation mark, U+201A NEW
            _entityName.Add(8218, "sbquo");
            _entityValue.Add("ldquo", 8220); // left double quotation mark, U+201C ISOnum
            _entityName.Add(8220, "ldquo");
            _entityValue.Add("rdquo", 8221); // right double quotation mark, U+201D ISOnum
            _entityName.Add(8221, "rdquo");
            _entityValue.Add("bdquo", 8222); // double low-9 quotation mark, U+201E NEW
            _entityName.Add(8222, "bdquo");
            _entityValue.Add("dagger", 8224); // dagger, U+2020 ISOpub
            _entityName.Add(8224, "dagger");
            _entityValue.Add("Dagger", 8225); // double dagger, U+2021 ISOpub
            _entityName.Add(8225, "Dagger");
            _entityValue.Add("permil", 8240); // per mille sign, U+2030 ISOtech
            _entityName.Add(8240, "permil");
            _entityValue.Add("lsaquo", 8249); // single left-pointing angle quotation mark, U+2039 ISO proposed
            _entityName.Add(8249, "lsaquo");
            _entityValue.Add("rsaquo", 8250); // single right-pointing angle quotation mark, U+203A ISO proposed
            _entityName.Add(8250, "rsaquo");
            _entityValue.Add("euro", 8364); // euro sign, U+20AC NEW
            _entityName.Add(8364, "euro");

            _maxEntitySize = 8 + 1; // we add the # char

            #endregion
        }

        private HtmlEntity()
        {
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Replace known entities by characters.
        /// </summary>
        /// <param name="text">The source text.</param>
        /// <returns>The result text.</returns>
        public static string DeEntitize(string text)
        {
            if (text == null)
                return null;

            if (text.Length == 0)
                return text;

            StringBuilder sb = new StringBuilder(text.Length);
            ParseState state = ParseState.Text;
            StringBuilder entity = new StringBuilder(10);

            for (int i = 0; i < text.Length; i++)
            {
                switch (state)
                {
                    case ParseState.Text:
                        switch (text[i])
                        {
                            case '&':
                                state = ParseState.EntityStart;
                                break;

                            default:
                                sb.Append(text[i]);
                                break;
                        }
                        break;

                    case ParseState.EntityStart:
                        switch (text[i])
                        {
                            case ';':
                                if (entity.Length == 0)
                                {
                                    sb.Append("&;");
                                }
                                else
                                {
                                    if (entity[0] == '#')
                                    {
                                        string e = entity.ToString();
                                        try
 										{
											string codeStr = e.Substring(1).Trim().ToLower();
											int fromBase;
											if (codeStr.StartsWith("x"))
											{
												fromBase = 16;
												codeStr = codeStr.Substring(1);
											}
											else
											{
												fromBase = 10;
											}
											int code = Convert.ToInt32(codeStr, fromBase);
 											sb.Append(Convert.ToChar(code));
 										}
                                        catch
                                        {
                                            sb.Append("&#" + e + ";");
                                        }
                                    }
                                    else
                                    {
                                        // named entity?
                                        int code;
                                        object o = _entityValue[entity.ToString()];
                                        if (o == null)
                                        {
                                            // nope
                                            sb.Append("&" + entity + ";");
                                        }
                                        else
                                        {
                                            // we found one
                                            code = (int) o;
                                            sb.Append(Convert.ToChar(code));
                                        }
                                    }
                                    entity.Remove(0, entity.Length);
                                }
                                state = ParseState.Text;
                                break;

                            case '&':
                                // new entity start without end, it was not an entity...
                                sb.Append("&" + entity);
                                entity.Remove(0, entity.Length);
                                break;

                            default:
                                entity.Append(text[i]);
                                if (entity.Length > _maxEntitySize)
                                {
                                    // unknown stuff, just don't touch it
                                    state = ParseState.Text;
                                    sb.Append("&" + entity);
                                    entity.Remove(0, entity.Length);
                                }
                                break;
                        }
                        break;
                }
            }

            // finish the work
            if (state == ParseState.EntityStart)
            {
                sb.Append("&" + entity);
            }
            return sb.ToString();
        }

        /// <summary>
        /// Clone and entitize an HtmlNode. This will affect attribute values and nodes' text. It will also entitize all child nodes.
        /// </summary>
        /// <param name="node">The node to entitize.</param>
        /// <returns>An entitized cloned node.</returns>
        public static HtmlNode Entitize(HtmlNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            HtmlNode result = node.CloneNode(true);
            if (result.HasAttributes)
                Entitize(result.Attributes);

            if (result.HasChildNodes)
            {
                Entitize(result.ChildNodes);
            }
            else
            {
                if (result.NodeType == HtmlNodeType.Text)
                {
                    ((HtmlTextNode) result).Text = Entitize(((HtmlTextNode) result).Text, true, true);
                }
            }
            return result;
        }

        /// <summary>
        /// Replace characters above 127 by entities.
        /// </summary>
        /// <param name="text">The source text.</param>
        /// <returns>The result text.</returns>
        public static string Entitize(string text)
        {
            return Entitize(text, true);
        }

        /// <summary>
        /// Replace characters above 127 by entities.
        /// </summary>
        /// <param name="text">The source text.</param>
        /// <param name="useNames">If set to false, the function will not use known entities name. Default is true.</param>
        /// <returns>The result text.</returns>
        public static string Entitize(string text, bool useNames)
        {
            return Entitize(text, useNames, false);
        }

        /// <summary>
        /// Replace characters above 127 by entities.
        /// </summary>
        /// <param name="text">The source text.</param>
        /// <param name="useNames">If set to false, the function will not use known entities name. Default is true.</param>
        /// <param name="entitizeQuotAmpAndLtGt">If set to true, the [quote], [ampersand], [lower than] and [greather than] characters will be entitized.</param>
        /// <returns>The result text</returns>
        public static string Entitize(string text, bool useNames, bool entitizeQuotAmpAndLtGt)
//		_entityValue.Add("quot", 34);	// quotation mark = APL quote, U+0022 ISOnum
//		_entityName.Add(34, "quot");
//		_entityValue.Add("amp", 38);	// ampersand, U+0026 ISOnum
//		_entityName.Add(38, "amp");
//		_entityValue.Add("lt", 60);	// less-than sign, U+003C ISOnum
//		_entityName.Add(60, "lt");
//		_entityValue.Add("gt", 62);	// greater-than sign, U+003E ISOnum
//		_entityName.Add(62, "gt");
        {
            if (text == null)
                return null;

            if (text.Length == 0)
                return text;

            StringBuilder sb = new StringBuilder(text.Length);
            for (int i = 0; i < text.Length; i++)
            {
                int code = text[i];
                if ((code > 127) ||
                    (entitizeQuotAmpAndLtGt && ((code == 34) || (code == 38) || (code == 60) || (code == 62))))
                {
                    string entity = _entityName[code] as string;
                    if ((entity == null) || (!useNames))
                    {
                        sb.Append("&#" + code + ";");
                    }
                    else
                    {
                        sb.Append("&" + entity + ";");
                    }
                }
                else
                {
                    sb.Append(text[i]);
                }
            }

            return sb.ToString();
        }

        #endregion

        #region Private Methods

        private static void Entitize(HtmlAttributeCollection collection)
        {
            foreach (HtmlAttribute at in collection)
            {
                at.Value = Entitize(at.Value);
            }
        }

        private static void Entitize(HtmlNodeCollection collection)
        {
            foreach (HtmlNode node in collection)
            {
                if (node.HasAttributes)
                    Entitize(node.Attributes);

                if (node.HasChildNodes)
                {
                    Entitize(node.ChildNodes);
                }
                else
                {
                    if (node.NodeType == HtmlNodeType.Text)
                    {
                        ((HtmlTextNode) node).Text = Entitize(((HtmlTextNode) node).Text, true, true);
                    }
                }
            }
        }

        #endregion

        #region Nested type: ParseState

        private enum ParseState
        {
            Text,
            EntityStart
        }

        #endregion
    }
}


text:
J2OBJC_STATIC_FIELD_GETTER(OrgBouncycastleMathRawMont256, M, jlong)

@implementation OrgBouncycastleMathRawMont256

+ (jint)inverse32WithInt:(jint)x {
  return OrgBouncycastleMathRawMont256_inverse32WithInt_(x);
}

+ (void)multAddWithIntArray:(IOSIntArray *)x
               withIntArray:(IOSIntArray *)y
               withIntArray:(IOSIntArray *)z
               withIntArray:(IOSIntArray *)m
                    withInt:(jint)mInv32 {
  OrgBouncycastleMathRawMont256_multAddWithIntArray_withIntArray_withIntArray_withIntArray_withInt_(x, y, z, m, mInv32);
}

+ (void)multAddXFWithIntArray:(IOSIntArray *)x
                 withIntArray:(IOSIntArray *)y
                 withIntArray:(IOSIntArray *)z
                 withIntArray:(IOSIntArray *)m {
  OrgBouncycastleMathRawMont256_multAddXFWithIntArray_withIntArray_withIntArray_withIntArray_(x, y, z, m);
}

+ (void)reduceWithIntArray:(IOSIntArray *)z
              withIntArray:(IOSIntArray *)m
                   withInt:(jint)mInv32 {
  OrgBouncycastleMathRawMont256_reduceWithIntArray_withIntArray_withInt_(z, m, mInv32);
}

+ (void)reduceXFWithIntArray:(IOSIntArray *)z
                withIntArray:(IOSIntArray *)m {
  OrgBouncycastleMathRawMont256_reduceXFWithIntArray_withIntArray_(z, m);
}

- (instancetype)init {
  OrgBouncycastleMathRawMont256_init(self);
  return self;
}

@end

jint OrgBouncycastleMathRawMont256_inverse32WithInt_(jint x) {
  OrgBouncycastleMathRawMont256_initialize();
  jint z = x;
  z *= 2 - x * z;
  z *= 2 - x * z;
  z *= 2 - x * z;
  z *= 2 - x * z;
  return z;
}

void OrgBouncycastleMathRawMont256_multAddWithIntArray_withIntArray_withIntArray_withIntArray_withInt_(IOSIntArray *x, IOSIntArray *y, IOSIntArray *z, IOSIntArray *m, jint mInv32) {
  OrgBouncycastleMathRawMont256_initialize();
  jint z_8 = 0;
  jlong y_0 = IOSIntArray_Get(nil_chk(y), 0) & OrgBouncycastleMathRawMont256_M;
  for (jint i = 0; i < 8; ++i) {
    jlong z_0 = IOSIntArray_Get(nil_chk(z), 0) & OrgBouncycastleMathRawMont256_M;
    jlong x_i = IOSIntArray_Get(nil_chk(x), i) & OrgBouncycastleMathRawMont256_M;
    jlong prod1 = x_i * y_0;
    jlong carry = (prod1 & OrgBouncycastleMathRawMont256_M) + z_0;
    jlong t = ((jint) carry * mInv32) & OrgBouncycastleMathRawMont256_M;
    jlong prod2 = t * (IOSIntArray_Get(nil_chk(m), 0) & OrgBouncycastleMathRawMont256_M);
    carry += (prod2 & OrgBouncycastleMathRawMont256_M);
    carry = (URShift64(carry, 32)) + (URShift64(prod1, 32)) + (URShift64(prod2, 32));
    for (jint j = 1; j < 8; ++j) {
      prod1 = x_i * (IOSIntArray_Get(y, j) & OrgBouncycastleMathRawMont256_M);
      prod2 = t * (IOSIntArray_Get(m, j) & OrgBouncycastleMathRawMont256_M);
      carry += (prod1 & OrgBouncycastleMathRawMont256_M) + (prod2 & OrgBouncycastleMathRawMont256_M) + (IOSIntArray_Get(z, j) & OrgBouncycastleMathRawMont256_M);
      *IOSIntArray_GetRef(z, j - 1) = (jint) carry;
      carry = (URShift64(carry, 32)) + (URShift64(prod1, 32)) + (URShift64(prod2, 32));
    }
    carry += (z_8 & OrgBouncycastleMathRawMont256_M);
    *IOSIntArray_GetRef(z, 7) = (jint) carry;
    z_8 = (jint) (URShift64(carry, 32));
  }
  if (z_8 != 0 || OrgBouncycastleMathRawNat256_gteWithIntArray_withIntArray_(z, m)) {
    OrgBouncycastleMathRawNat256_subWithIntArray_withIntArray_withIntArray_(z, m, z);
  }
}

void OrgBouncycastleMathRawMont256_multAddXFWithIntArray_withIntArray_withIntArray_withIntArray_(IOSIntArray *x, IOSIntArray *y, IOSIntArray *z, IOSIntArray *m) {
  OrgBouncycastleMathRawMont256_initialize();
  jint z_8 = 0;
  jlong y_0 = IOSIntArray_Get(nil_chk(y), 0) & OrgBouncycastleMathRawMont256_M;
  for (jint i = 0; i < 8; ++i) {
    jlong x_i = IOSIntArray_Get(nil_chk(x), i) & OrgBouncycastleMathRawMont256_M;
    jlong carry = x_i * y_0 + (IOSIntArray_Get(nil_chk(z), 0) & OrgBouncycastleMathRawMont256_M);
    jlong t = carry & OrgBouncycastleMathRawMont256_M;
    carry = (URShift64(carry, 32)) + t;
    for (jint j = 1; j < 8; ++j) {
      jlong prod1 = x_i * (IOSIntArray_Get(y, j) & OrgBouncycastleMathRawMont256_M);
      jlong prod2 = t * (IOSIntArray_Get(nil_chk(m), j) & OrgBouncycastleMathRawMont256_M);
      carry += (prod1 & OrgBouncycastleMathRawMont256_M) + (prod2 & OrgBouncycastleMathRawMont256_M) + (IOSIntArray_Get(z, j) & OrgBouncycastleMathRawMont256_M);
      *IOSIntArray_GetRef(z, j - 1) = (jint) carry;
      carry = (URShift64(carry, 32)) + (URShift64(prod1, 32)) + (URShift64(prod2, 32));
    }
    carry += (z_8 & OrgBouncycastleMathRawMont256_M);
    *IOSIntArray_GetRef(z, 7) = (jint) carry;
    z_8 = (jint) (URShift64(carry, 32));
  }
  if (z_8 != 0 || OrgBouncycastleMathRawNat256_gteWithIntArray_withIntArray_(z, m)) {
    OrgBouncycastleMathRawNat256_subWithIntArray_withIntArray_withIntArray_(z, m, z);
  }
}

void OrgBouncycastleMathRawMont256_reduceWithIntArray_withIntArray_withInt_(IOSIntArray *z, IOSIntArray *m, jint mInv32) {
  OrgBouncycastleMathRawMont256_initialize();
  for (jint i = 0; i < 8; ++i) {
    jint z_0 = IOSIntArray_Get(nil_chk(z), 0);
    jlong t = (z_0 * mInv32) & OrgBouncycastleMathRawMont256_M;
    jlong carry = t * (IOSIntArray_Get(nil_chk(m), 0) & OrgBouncycastleMathRawMont256_M) + (z_0 & OrgBouncycastleMathRawMont256_M);
    URShiftAssignLong(&carry, 32);
    for (jint j = 1; j < 8; ++j) {
      carry += t * (IOSIntArray_Get(m, j) & OrgBouncycastleMathRawMont256_M) + (IOSIntArray_Get(z, j) & OrgBouncycastleMathRawMont256_M);
      *IOSIntArray_GetRef(z, j - 1) = (jint) carry;
      URShiftAssignLong(&carry, 32);
    }
    *IOSIntArray_GetRef(z, 7) = (jint) carry;
  }
  if (OrgBouncycastleMathRawNat256_gteWithIntArray_withIntArray_(z, m)) {
    OrgBouncycastleMathRawNat256_subWithIntArray_withIntArray_withIntArray_(z, m, z);
  }
}

void OrgBouncycastleMathRawMont256_reduceXFWithIntArray_withIntArray_(IOSIntArray *z, IOSIntArray *m) {
  OrgBouncycastleMathRawMont256_initialize();
  for (jint i = 0; i < 8; ++i) {
    jint z_0 = IOSIntArray_Get(nil_chk(z), 0);
    jlong t = z_0 & OrgBouncycastleMathRawMont256_M;
    jlong carry = t;
    for (jint j = 1; j < 8; ++j) {
      carry += t * (IOSIntArray_Get(nil_chk(m), j) & OrgBouncycastleMathRawMont256_M) + (IOSIntArray_Get(z, j) & OrgBouncycastleMathRawMont256_M);
      *IOSIntArray_GetRef(z, j - 1) = (jint) carry;
      URShiftAssignLong(&carry, 32);
    }
    *IOSIntArray_GetRef(z, 7) = (jint) carry;
  }
  if (OrgBouncycastleMathRawNat256_gteWithIntArray_withIntArray_(z, m)) {
    OrgBouncycastleMathRawNat256_subWithIntArray_withIntArray_withIntArray_(z, m, z);
  }
}

void OrgBouncycastleMathRawMont256_init(OrgBouncycastleMathRawMont256 *self) {
  (void) NSObject_init(self);
}

J2OBJC_CLASS_TYPE_LITERAL_SOURCE(OrgBouncycastleMathRawMont256)

redpajama_set_name: RedPajamaGithub


text:
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using Amazon.DynamoDBv2.DocumentModel;
using System.IO;
using Amazon.DynamoDBv2.DataModel;
using CommonTests.Framework;
using NUnit.Framework;
using System.Threading.Tasks;

namespace CommonTests.IntegrationTests.DynamoDB
{
    public partial class DynamoDBTests : TestBase<AmazonDynamoDBClient>
    {
        [Test]
        [Category("DynamoDB")]
        public void TestContext()
        {
            RunAsSync(async () =>
            {
                foreach (var conversion in new DynamoDBEntryConversion[] { DynamoDBEntryConversion.V1, DynamoDBEntryConversion.V2 })
                {
                    TableCache.Clear();

                    // Cleanup existing data
                    CleanupTables();
                    // Recreate context
                    CreateContext(conversion);

                    await TestEmptyCollections(conversion);

                    await TestContextConversions();
                    await TestUnsupportedTypes();

                    await TestHashObjects();
                    await TestHashRangeObjects();
                    await TestOtherContextOperations();
                    await TestBatchOperations();
                }
            });
        }

        private static async Task TestUnsupportedTypes()
        {
            // Verify that saving objects with invalid properties result in exceptions
            var employee2 = new Employee2
            {
                Name = "Alan",
                Age = 31,
                TimeWithCompany = TimeSpan.FromDays(300)
            };
            await AssertExtensions.ExpectExceptionAsync<InvalidOperationException>(Context.SaveAsync(employee2),
                "Type System.TimeSpan is unsupported, it cannot be instantiated");
            var employee3 = new Employee3
            {
                Name = "Alan",
                Age = 31,
                EmptyProperty = new EmptyType()
            };
            await AssertExtensions.ExpectExceptionAsync<InvalidOperationException>(Context.SaveAsync(employee3),
                "Type CommonTests.IntegrationTests.DynamoDB.DynamoDBTests+EmptyType is unsupported, it has no supported members");

            // Verify that objects that are invalid result in exceptions
            AssertExtensions.ExpectException<InvalidOperationException>(() => Context.ScanAsync<TimeSpan>(new ScanCondition[]{}),
                "Type System.TimeSpan is unsupported, it cannot be instantiated");
            AssertExtensions.ExpectException<InvalidOperationException>(() => Context.ScanAsync<EmptyType>(new ScanCondition[] { }),
                "Type CommonTests.IntegrationTests.DynamoDB.DynamoDBTests+EmptyType is unsupported, it has no supported members");
        }

        private async Task TestContextConversions()
        {
            var conversionV1 = DynamoDBEntryConversion.V1;
            var conversionV2 = DynamoDBEntryConversion.V2;

            Product product = new Product
            {
                Id = 1,
                Name = "CloudSpotter",
                CompanyName = "CloudsAreGrate",
                Price = 1200,
                TagSet = new HashSet<string> { "Prod", "1.0" },
                CurrentStatus = Status.Active,
                InternalId = "T1000",
                IsPublic = true,
                AlwaysN = true,
                Rating = 4,
                Components = new List<string> { "Code", "Coffee" },
                KeySizes = new List<byte> { 16, 64, 128 },
                CompanyInfo = new CompanyInfo
                {
                    Name = "MyCloud",
                    Founded = new DateTime(1994, 7, 6),
                    Revenue = 9001
                }
            };

            {
                var docV1 = Context.ToDocument(product, new DynamoDBOperationConfig { Conversion = conversionV1 });
                var docV2 = Context.ToDocument(product, new DynamoDBOperationConfig { Conversion = conversionV2 });
                VerifyConversions(docV1, docV2);
            }

            {
                using (var contextV1 = new DynamoDBContext(Client, new DynamoDBContextConfig { Conversion = conversionV1 }))
                using (var contextV2 = new DynamoDBContext(Client, new DynamoDBContextConfig { Conversion = conversionV2 }))
                {
                    var docV1 = contextV1.ToDocument(product);
                    var docV2 = contextV2.ToDocument(product);
                    VerifyConversions(docV1, docV2);
                }
            }

            {
                using (var contextV1 = new DynamoDBContext(Client, new DynamoDBContextConfig { Conversion = conversionV1 }))
                {
                    await contextV1.SaveAsync(product);
                    await contextV1.SaveAsync(product, new DynamoDBOperationConfig { Conversion = conversionV2 });
                }
            }

            // Introduce a circular reference and try to serialize
            {
                product.CompanyInfo = new CompanyInfo
                {
                    Name = "MyCloud",
                    Founded = new DateTime(1994, 7, 6),
                    Revenue = 9001,
                    MostPopularProduct = product
                };
                AssertExtensions.ExpectException<InvalidOperationException>(() => Context.ToDocument(product));
                AssertExtensions.ExpectException<InvalidOperationException>(() => Context.ToDocument(product, new DynamoDBOperationConfig { Conversion = conversionV1 }));
                AssertExtensions.ExpectException<InvalidOperationException>(() => Context.ToDocument(product, new DynamoDBOperationConfig { Conversion = conversionV2 }));

                // Remove circular dependence
                product.CompanyInfo.MostPopularProduct = new Product
                {
                    Id = 3,
                    Name = "CloudDebugger",
                    CompanyName = "CloudsAreGrate",
                    Price = 9000,
                    TagSet = new HashSet<string> { "Test" },
                };

                var docV1 = Context.ToDocument(product, new DynamoDBOperationConfig { Conversion = conversionV1 });
                var docV2 = Context.ToDocument(product, new DynamoDBOperationConfig { Conversion = conversionV2 });
                VerifyConversions(docV1, docV2);
            }

            // Introduce circular reference in a Document and try to deserialize
            {
                // Normal serialization
                var docV1 = Context.ToDocument(product, new DynamoDBOperationConfig { Conversion = conversionV1 });
                var docV2 = Context.ToDocument(product, new DynamoDBOperationConfig { Conversion = conversionV2 });
                VerifyConversions(docV1, docV2);

                // Add circular references
                docV1["CompanyInfo"].AsDocument()["MostPopularProduct"] = docV1;
                docV2["CompanyInfo"].AsDocument()["MostPopularProduct"] = docV2;
                AssertExtensions.ExpectException(() => Context.FromDocument<Product>(docV1, new DynamoDBOperationConfig { Conversion = conversionV1 }));
                AssertExtensions.ExpectException(() => Context.FromDocument<Product>(docV2, new DynamoDBOperationConfig { Conversion = conversionV2 }));

                // Remove circular references
                docV1["CompanyInfo"].AsDocument()["MostPopularProduct"] = null;
                docV2["CompanyInfo"].AsDocument()["MostPopularProduct"] = docV1;
                var prod1 = Context.FromDocument<Product>(docV1, new DynamoDBOperationConfig { Conversion = conversionV1 });
                var prod2 = Context.FromDocument<Product>(docV2, new DynamoDBOperationConfig { Conversion = conversionV2 });
            }

        }

        private static void VerifyConversions(Document docV1, Document docV2)
        {
            Assert.AreEqual(1, docV1["Id"].AsInt());
            Assert.AreEqual("CloudSpotter", docV1["Product"].AsString());
            Assert.IsNotNull(docV1["Components"].AsPrimitiveList());
            Assert.IsNotNull(docV1["IsPublic"].AsPrimitive());
            Assert.IsNotNull(docV1["Tags"].AsPrimitiveList());
            Assert.IsNotNull(docV1["CompanyInfo"] as Document);
            Assert.IsNotNull(docV1["KeySizes"].AsPrimitiveList());

            Assert.AreEqual(1, docV2["Id"].AsInt());
            Assert.AreEqual("CloudSpotter", docV2["Product"].AsString());
            Assert.IsNull(docV2["Components"].AsPrimitiveList());
            Assert.IsNotNull(docV2["Components"].AsDynamoDBList());
            Assert.IsNull(docV2["IsPublic"].AsPrimitive());
            Assert.IsNotNull(docV2["IsPublic"].AsDynamoDBBool());
            Assert.IsNotNull(docV2["Tags"].AsPrimitiveList());
            Assert.IsNotNull(docV2["CompanyInfo"] as Document);
            Assert.IsNotNull(docV2["KeySizes"].AsPrimitiveList());
        }

        private async Task TestEmptyCollections(DynamoDBEntryConversion conversion)
        {
            // Check if the conversion being used is V1
            // In V1 conversion, lists are stored as sets, which cannot
            // be empty, so for V1 we are not testing empty lists
            var isV1 = (conversion == DynamoDBEntryConversion.V1);

            // Create and save item
            Product product = new Product
            {
                Id = 1,
                Map = new Dictionary<string, string>()
            };
            if (!isV1)
                product.Components = new List<string>();

            await Context.SaveAsync(product);

            // Load and test the item
            var retrieved = await Context.LoadAsync(product);
            if (!isV1)
            {
                Assert.IsNotNull(retrieved.Components);
                Assert.AreEqual(0, retrieved.Components.Count);
            }
            Assert.IsNotNull(retrieved.Map);
            Assert.AreEqual(0, retrieved.Map.Count);
        }
        private async Task TestHashObjects()
        {
            // Create and save item
            Product product = new Product
            {
                Id = 1,
                Name = "CloudSpotter",
                CompanyName = "CloudsAreGrate",
                Price = 1200,
                TagSet = new HashSet<string> { "Prod", "1.0" },
                CurrentStatus = Status.Active,
                InternalId = "T1000",
                IsPublic = true,
                AlwaysN = true,
                Rating = 4,
                Components = new List<string> { "Code", "Coffee" },
                KeySizes = new List<byte> { 16, 64, 128 },
                CompanyInfo = new CompanyInfo
                {
                    Name = "MyCloud",
                    Founded = new DateTime(1994, 7, 6),
                    Revenue = 9001,
                    AllProducts = new List<Product>
                    {
                        new Product { Id = 12, Name = "CloudDebugger" },
                        new Product { Id = 13, Name = "CloudDebuggerTester" }
                    },
                    CompetitorProducts = new Dictionary<string, List<Product>>
                    {
                        {
                            "CloudsAreOK",
                            new List<Product>
                            {
                                new Product { Id = 90, Name = "CloudSpotter RipOff" },
                                new Product { Id = 100, Name = "CloudDebugger RipOff" },
                            }
                        },
                        {
                            "CloudsAreBetter",
                            new List<Product>
                            {
                                new Product { Id = 92, Name = "CloudSpotter RipOff 2" },
                                new Product { Id = 102, Name = "CloudDebugger RipOff 3" },
                            }
                        },
                    }
                },
                Map = new Dictionary<string, string>
                {
                    { "a", "1" },
                    { "b", "2" }
                }
            };
            await Context.SaveAsync(product);

            // Test conversion
            var doc = Context.ToDocument(product);
            Assert.IsNotNull(doc["Tags"].AsPrimitiveList());
            //if (DynamoDBEntryConversion.Schema == DynamoDBEntryConversion.ConversionSchema.V1)
            //    Assert.IsNotNull(doc["Components"].AsPrimitiveList());
            //else
            //    Assert.IsNotNull(doc["Components"].AsDynamoDBList());
            Assert.IsTrue(
                doc["Components"].AsPrimitiveList() != null ||
                doc["Components"].AsDynamoDBList() != null);
            Assert.IsNotNull(doc["CompanyInfo"].AsDocument());

            // Load item
            Product retrieved = await Context.LoadAsync<Product>(1);
            Assert.AreEqual(product.Id, retrieved.Id);
            Assert.AreEqual(product.TagSet.Count, retrieved.TagSet.Count);
            Assert.AreEqual(product.Components.Count, retrieved.Components.Count);
            Assert.IsNull(retrieved.InternalId);
            Assert.AreEqual(product.CurrentStatus, retrieved.CurrentStatus);
            Assert.AreEqual(product.IsPublic, retrieved.IsPublic);
            Assert.AreEqual(product.Rating, retrieved.Rating);
            Assert.AreEqual(product.KeySizes.Count, retrieved.KeySizes.Count);
            Assert.IsNotNull(retrieved.CompanyInfo);
            Assert.AreEqual(product.CompanyInfo.Name, retrieved.CompanyInfo.Name);
            Assert.AreEqual(product.CompanyInfo.Founded, retrieved.CompanyInfo.Founded);
            Assert.AreNotEqual(product.CompanyInfo.Revenue, retrieved.CompanyInfo.Revenue);
            Assert.AreEqual(product.CompanyInfo.AllProducts.Count, retrieved.CompanyInfo.AllProducts.Count);
            Assert.AreEqual(product.CompanyInfo.AllProducts[0].Id, retrieved.CompanyInfo.AllProducts[0].Id);
            Assert.AreEqual(product.CompanyInfo.AllProducts[1].Id, retrieved.CompanyInfo.AllProducts[1].Id);
            Assert.AreEqual(product.Map.Count, retrieved.Map.Count);
            Assert.AreEqual(product.CompanyInfo.CompetitorProducts.Count, retrieved.CompanyInfo.CompetitorProducts.Count);
            Assert.AreEqual(product.CompanyInfo.CompetitorProducts.ElementAt(0).Key, retrieved.CompanyInfo.CompetitorProducts.ElementAt(0).Key);
            Assert.AreEqual(product.CompanyInfo.CompetitorProducts.ElementAt(0).Value.Count, retrieved.CompanyInfo.CompetitorProducts.ElementAt(0).Value.Count);
            Assert.AreEqual(product.CompanyInfo.CompetitorProducts.ElementAt(1).Key, retrieved.CompanyInfo.CompetitorProducts.ElementAt(1).Key);
            Assert.AreEqual(product.CompanyInfo.CompetitorProducts.ElementAt(1).Value.Count, retrieved.CompanyInfo.CompetitorProducts.ElementAt(1).Value.Count);

            // Try saving circularly-referencing object
            product.CompanyInfo.AllProducts.Add(product);
            await AssertExtensions.ExpectExceptionAsync(Context.SaveAsync(product));
            product.CompanyInfo.AllProducts.RemoveAt(2);

            // Create and save new item
            product.Id++;
            product.Price = 94;
            product.TagSet = null;
            product.Components = null;
            product.CurrentStatus = Status.Upcoming;
            product.IsPublic = false;
            product.AlwaysN = false;
            product.Rating = null;
            product.KeySizes = null;
            await Context.SaveAsync(product);

            // Load new item
            retrieved = await Context.LoadAsync<Product>(product);
            Assert.AreEqual(product.Id, retrieved.Id);
            Assert.IsNull(retrieved.TagSet);
            Assert.IsNull(retrieved.Components);
            Assert.IsNull(retrieved.InternalId);
            Assert.AreEqual(product.CurrentStatus, retrieved.CurrentStatus);
            Assert.AreEqual(product.IsPublic, retrieved.IsPublic);
            Assert.AreEqual(product.AlwaysN, retrieved.AlwaysN);
            Assert.AreEqual(product.Rating, retrieved.Rating);
            Assert.IsNull(retrieved.KeySizes);

            // Enumerate all products and save their Ids
            List<int> productIds = new List<int>();
            IEnumerable<Product> products = await Context.ScanAsync<Product>(new ScanCondition[]{}).GetRemainingAsync();
            foreach(var p in products)
            {
                productIds.Add(p.Id);
            }
            Assert.AreEqual(2, productIds.Count);

            // Load first product
            var firstId = productIds[0];
            product = await Context.LoadAsync<Product>(firstId);
            Assert.IsNotNull(product);
            Assert.AreEqual(firstId, product.Id);

            // Query GlobalIndex
            products = await Context.QueryAsync<Product>(
                product.CompanyName,            // Hash-key for the index is Company
                QueryOperator.GreaterThan,      // Range-key for the index is Price, so the
                new object[] { 90 },            // condition is against a numerical value
                new DynamoDBOperationConfig     // Configure the index to use
                {
                    IndexName = "GlobalIndex",
                }).GetRemainingAsync();
            Assert.AreEqual(2, products.Count());

            // Query GlobalIndex with an additional non-key condition
            products = await Context.QueryAsync<Product>(
                product.CompanyName,            // Hash-key for the index is Company
                QueryOperator.GreaterThan,      // Range-key for the index is Price, so the
                new object[] { 90 },            // condition is against a numerical value
                new DynamoDBOperationConfig     // Configure the index to use
                {
                    IndexName = "GlobalIndex",
                    QueryFilter = new List<ScanCondition>
                    {
                        new ScanCondition("TagSet", ScanOperator.Contains, "1.0")
                    }
                }).GetRemainingAsync();
            Assert.AreEqual(1, products.Count());

            // Delete first product
            await Context.DeleteAsync<Product>(firstId);
            product = await Context.LoadAsync<Product>(product.Id);
            Assert.IsNull(product);

            // Scan the table
            products = await Context.ScanAsync<Product>(new ScanCondition[] { }).GetRemainingAsync();
            Assert.AreEqual(1, products.Count());

            // Test a versioned product
            VersionedProduct vp = new VersionedProduct
            {
                Id = 3,
                Name = "CloudDebugger",
                CompanyName = "CloudsAreGrate",
                Price = 9000,
                TagSet = new HashSet<string> { "Test" },
            };
            await Context.SaveAsync(vp);

            // Update and save
            vp.Price++;
            await Context.SaveAsync(vp);

            // Alter the version and try to save
            vp.Version = 0;
            await AssertExtensions.ExpectExceptionAsync(Context.SaveAsync(vp));

            // Load and save
            vp = await Context.LoadAsync(vp);
            await Context.SaveAsync(vp);
        }

        private async Task TestHashRangeObjects()
        {
            // Create and save item
            Employee employee = new Employee
            {
                Name = "Alan",
                Age = 31,
                CompanyName = "Big River",
                CurrentStatus = Status.Active,
                Score = 120,
                ManagerName = "Barbara",
                InternalId = "Alan@BigRiver",
                Aliases = new List<string> { "Al", "Steve" },
                Data = Encoding.UTF8.GetBytes("Some binary data"),
            };
            await Context.SaveAsync(employee);

            // Load item
            Employee retrieved = await Context.LoadAsync(employee);
            Assert.AreEqual(employee.Name, retrieved.Name);
            Assert.AreEqual(employee.Age, retrieved.Age);
            Assert.AreEqual(employee.CompanyName, retrieved.CompanyName);
            Assert.AreEqual(employee.CurrentStatus, retrieved.CurrentStatus);

            // Create and save new item
            employee.Name = "Chuck";
            employee.Age = 30;
            employee.CurrentStatus = Status.Inactive;
            employee.Aliases = new List<string> { "Charles" };
            employee.Data = Encoding.UTF8.GetBytes("Binary data");
            employee.Score = 94;
            await Context.SaveAsync(employee);

            // Load item
            retrieved = await Context.LoadAsync(employee);
            Assert.AreEqual(employee.Name, retrieved.Name);
            Assert.AreEqual(employee.Age, retrieved.Age);
            Assert.AreEqual(employee.CompanyName, retrieved.CompanyName);
            Assert.AreEqual(employee.CurrentStatus, retrieved.CurrentStatus);
            Assert.AreEqual(employee.Data.Length, retrieved.Data.Length);

            // Create more items
            Employee employee2 = new Employee
            {
                Name = "Diane",
                Age = 40,
                CompanyName = "Madeira",
                Score = 140,
                ManagerName = "Eva",
                Data = new byte[] { 1, 2, 3 },
                CurrentStatus = Status.Upcoming,
                InternalId = "Diane@Madeira",
            };
            await Context.SaveAsync(employee2);
            employee2.Age = 24;
            employee2.Score = 101;
            await Context.SaveAsync(employee2);

            retrieved = await Context.LoadAsync<Employee>("Alan", 31);
            Assert.AreEqual(retrieved.Name, "Alan");
            retrieved = await Context.LoadAsync(employee);
            Assert.AreEqual(retrieved.Name, "Chuck");
            retrieved = await Context.LoadAsync(employee2, new DynamoDBOperationConfig { ConsistentRead = true });
            Assert.AreEqual(retrieved.Name, "Diane");
            Assert.AreEqual(retrieved.Age, 24);

            // Scan for all items
            var employees = await Context.ScanAsync<Employee>(new ScanCondition[]{}).GetRemainingAsync();
            Assert.AreEqual(4, employees.Count);

            // Query for items with Hash-Key = "Diane"
            employees = await Context.QueryAsync<Employee>("Diane").GetRemainingAsync();
            Assert.AreEqual(2, employees.Count);

            // Query for items with Hash-Key = "Diane" and Range-Key > 30
            employees = await Context.QueryAsync<Employee>("Diane", QueryOperator.GreaterThan, new object[] { 30 }).GetRemainingAsync();
            Assert.AreEqual(1, employees.Count);

            // Index Query

            // Query local index for items with Hash-Key = "Diane"
            employees = await Context.QueryAsync<Employee>("Diane", new DynamoDBOperationConfig { IndexName = "LocalIndex" }).GetRemainingAsync();
            Assert.AreEqual(2, employees.Count);

            // Query local index for items with Hash-Key = "Diane" and Range-Key = "Eva"
            employees = await Context.QueryAsync<Employee>("Diane", QueryOperator.Equal, new object[] { "Eva" },
                new DynamoDBOperationConfig { IndexName = "LocalIndex" }).GetRemainingAsync();
            Assert.AreEqual(2, employees.Count);

            // Query global index for item with Hash-Key (Company) = "Big River"
            employees = await Context.QueryAsync<Employee>("Big River", new DynamoDBOperationConfig { IndexName = "GlobalIndex" }).GetRemainingAsync();
            Assert.AreEqual(2, employees.Count);

            // Query global index for item with Hash-Key (Company) = "Big River", with QueryFilter for CurrentStatus = Status.Active
            employees = await Context.QueryAsync<Employee>("Big River",
                new DynamoDBOperationConfig
                {
                    IndexName = "GlobalIndex",
                    QueryFilter = new List<ScanCondition>
                    {
                        new ScanCondition("CurrentStatus", ScanOperator.Equal, Status.Active)
                    }
                }).GetRemainingAsync();
            Assert.AreEqual(1, employees.Count);

            // Index Scan

            // Scan local index for items with Hash-Key = "Diane"
            employees = await Context.ScanAsync<Employee>(
                new List<ScanCondition> { new ScanCondition("Name", ScanOperator.Equal, "Diane") },
                new DynamoDBOperationConfig { IndexName = "LocalIndex" }).GetRemainingAsync();
            Assert.AreEqual(2, employees.Count);

            // Scan local index for items with Hash-Key = "Diane" and Range-Key = "Eva"
            employees = await Context.ScanAsync<Employee>(
                new List<ScanCondition>
                {
                    new ScanCondition("Name", ScanOperator.Equal, "Diane"),
                    new ScanCondition("ManagerName", ScanOperator.Equal, "Eva")
                },
                new DynamoDBOperationConfig { IndexName = "LocalIndex" }).GetRemainingAsync();
            Assert.AreEqual(2, employees.Count);

            // Scan global index for item with Hash-Key (Company) = "Big River"
            employees = await Context.ScanAsync<Employee>(
                new List<ScanCondition> { new ScanCondition("CompanyName", ScanOperator.Equal, "Big River") },
                new DynamoDBOperationConfig { IndexName = "GlobalIndex" }).GetRemainingAsync();
            Assert.AreEqual(2, employees.Count);

            // Scan global index for item with Hash-Key (Company) = "Big River", with QueryFilter for CurrentStatus = Status.Active
            employees = await Context.ScanAsync<Employee>(
                new List<ScanCondition>
                {
                    new ScanCondition("CompanyName", ScanOperator.Equal, "Big River"),
                    new ScanCondition("CurrentStatus", ScanOperator.Equal, Status.Active)
                },
                new DynamoDBOperationConfig
                {
                    IndexName = "GlobalIndex"
                }).GetRemainingAsync();
            Assert.AreEqual(1, employees.Count);

        }

        private async Task TestBatchOperations()
        {
            int itemCount = 10;
            string employeePrefix = "Employee-";
            int employeeAgeStart = 20;
            int productIdStart = 90;
            string productPrefix = "Product-";

            var allEmployees = new List<Employee>();
            var batchWrite1 = Context.CreateBatchWrite<Employee>();
            var batchWrite2 = Context.CreateBatchWrite<Product>();
            for (int i = 0; i < itemCount; i++)
            {
                var employee = new Employee
                {
                    Name = employeePrefix + i,
                    Age = employeeAgeStart + i,
                    CompanyName = "Big River",
                    CurrentStatus = i % 2 == 0 ? Status.Active : Status.Inactive,
                    Score = 90 + i,
                    ManagerName = "Barbara",
                    InternalId = i + "@BigRiver",
                    Data = Encoding.UTF8.GetBytes(new string('@', i + 5))
                };
                allEmployees.Add(employee);
                batchWrite2.AddPutItem(new Product
                {
                    Id = productIdStart + i,
                    Name = productPrefix + i
                });
            }
            batchWrite1.AddPutItems(allEmployees);

            // Write both batches at once
            var multiTableWrite = Context.CreateMultiTableBatchWrite(batchWrite1, batchWrite2);
            await multiTableWrite.ExecuteAsync();

            // Create BatchGets
            var batchGet1 = Context.CreateBatchGet<Product>();
            var batchGet2 = Context.CreateBatchGet<Employee>();
            for (int i = 0; i < itemCount;i++ )
                batchGet1.AddKey(productIdStart + i, productPrefix + i);
            foreach (var employee in allEmployees)
                batchGet2.AddKey(employee);

            // Execute BatchGets together
            await Context.ExecuteBatchGetAsync(batchGet1, batchGet2);

            // Verify items are loaded
            Assert.AreEqual(itemCount, batchGet1.Results.Count);
            Assert.AreEqual(itemCount, batchGet2.Results.Count);
        }

        private async Task TestOtherContextOperations()
        {
            Employee employee1 = new Employee
            {
                Name = "Alan",
                Age = 31,
                CompanyName = "Big River",
                CurrentStatus = Status.Active,
                Score = 120,
                ManagerName = "Barbara",
                InternalId = "Alan@BigRiver",
                Aliases = new List<string> { "Al", "Steve" },
                Data = Encoding.UTF8.GetBytes("Some binary data")
            };

            Document doc = Context.ToDocument(employee1);
            Assert.AreEqual(employee1.Name, doc["Name"].AsString());
            Assert.AreEqual(employee1.Data.Length, doc["Data"].AsByteArray().Length);
            // Ignored properties are not propagated to the Document
            Assert.IsFalse(doc.ContainsKey("InternalId"));

            Employee roundtrip = Context.FromDocument<Employee>(doc);
            Assert.AreEqual(employee1.Name, roundtrip.Name);
            Assert.AreEqual(employee1.Data.Length, roundtrip.Data.Length);
            Assert.IsNull(roundtrip.InternalId);

            // Recreate the record
            await Context.DeleteAsync(employee1);
            await Context.SaveAsync(employee1);

            // Get record using Table instead of Context
            var table = Context.GetTargetTable<Employee>();
            Document retrieved = await table.GetItemAsync(doc);
            Assert.AreEqual(employee1.Name, doc["Name"].AsString());
            Assert.AreEqual(employee1.Data.Length, doc["Data"].AsByteArray().Length);
        }

        #region OPM definitions

        public enum Status { Active, Inactive, Upcoming, Obsolete, Removed }

        public class StatusConverter : IPropertyConverter
        {
            public DynamoDBEntry ToEntry(object value)
            {
                Status status = (Status)value;
                return new Primitive(status.ToString());
            }

            public object FromEntry(DynamoDBEntry entry)
            {
                Primitive primitive = entry.AsPrimitive();
                string text = primitive.AsString();
                Status status = (Status)Enum.Parse(typeof(Status), text);
                return status;
            }
        }

        /// <summary>
        /// Class representing items in the table [TableNamePrefix]HashTable
        /// </summary>
        [DynamoDBTable("HashTable")]
        public class Product
        {
            [DynamoDBHashKey]
            public int Id { get; set; }

            [DynamoDBProperty("Product")]
            public string Name { get; set; }

            [DynamoDBGlobalSecondaryIndexHashKey("GlobalIndex", AttributeName = "Company")]
            public string CompanyName { get; set; }

            public CompanyInfo CompanyInfo { get; set; }

            [DynamoDBGlobalSecondaryIndexRangeKey("GlobalIndex")]
            public int Price { get; set; }

            [DynamoDBProperty("Tags")]
            public HashSet<string> TagSet { get; set; }

            public MemoryStream Data { get; set; }

            [DynamoDBProperty(Converter = typeof(StatusConverter))]
            public Status CurrentStatus { get; set; }

            [DynamoDBIgnore]
            public string InternalId { get; set; }

            public bool IsPublic { get; set; }

            //[DynamoDBProperty(Converter = typeof(BoolAsNConverter))]
            public bool AlwaysN { get; set; }

            public int? Rating { get; set; }

            public List<string> Components { get; set; }

            //[DynamoDBProperty(Converter = typeof(SetPropertyConverter<List<byte>,byte>))]
            [DynamoDBProperty(Converter = typeof(ListToSetPropertyConverter<byte>))]
            public List<byte> KeySizes { get; set; }

            public Dictionary<string, string> Map { get; set; }
        }

        public class CompanyInfo
        {
            public string Name { get; set; }
            public DateTime Founded { get; set; }
            public Product MostPopularProduct { get; set; }
            public List<Product> AllProducts { get; set; }
            public Dictionary<string, List<Product>> CompetitorProducts { get; set; }

            [DynamoDBIgnore]
            public decimal Revenue { get; set; }
        }

        /// <summary>
        /// Class representing items in the table [TableNamePrefix]HashTable
        /// This class uses optimistic locking via the Version field
        /// </summary>
        public class VersionedProduct : Product
        {
            [DynamoDBVersion]
            public int? Version { get; set; }
        }

        /// <summary>
        /// Class representing items in the table [TableNamePrefix]HashRangeTable
        ///
        /// No DynamoDB attributes are defined on the type:
        /// -some attributes are inferred from the table
        /// -some attributes are defined in app.config
        /// </summary>
        public class Employee
        {
            // Hash key
            public string Name { get; set; }
            // Range key
            public int Age { get; set; }

            public string CompanyName { get; set; }
            public int Score { get; set; }
            public string ManagerName { get; set; }
            public byte[] Data { get; set; }
            public Status CurrentStatus { get; set; }
            public List<string> Aliases { get; set; }

            public string InternalId { get; set; }
        }

        /// <summary>
        /// Class with a property of a type that has no valid constructor
        /// </summary>
        public class Employee2 : Employee
        {
            public TimeSpan TimeWithCompany { get; set; }
        }

        /// <summary>
        /// Class with a property of an empty type
        /// </summary>
        public class Employee3 : Employee
        {
            public EmptyType EmptyProperty { get; set; }
        }

        /// <summary>
        /// Empty type
        /// </summary>
        public class EmptyType
        { }

        /// <summary>
        /// Class representing items in the table [TableNamePrefix]HashTable
        /// This class uses optimistic locking via the Version field
        /// </summary>
        public class VersionedEmployee : Employee
        {
            public int? Version { get; set; }
        }

        #endregion
    }
}


text:
This repository has the source for the C/C++ client libraries,
designed mostly for embedded systems, but perfectly suitable for
"regular" (POSIX, Windows) systems, too.

## Directory Organization

The directories of the library repository are:

- `core` : The core part, with modules portable to all, or most, libraries for
	specific platforms

- `lib` : Modules for libs that are available on more than one platform

- `windows` : Modules and Makefile for the Windows platform

- `posix` : Modules and Makefile for POSIX OSes (tested mostly on Linux)

- `openssl`: Modules and Makefile(s) for OpenSSL (on POSIX and Windows)

- `cpp`: Modules, Makefile(s) and examples for the C++ wrapper

- `contiki` : Modules and Makefile for the Contiki OS

- `freertos` : Modules and Makefile for the FreeRTOS OS


text:
<?php
namespace TYPO3\CMS\Form\Domain\Validator;

use TYPO3\CMS\Core\Utility\GeneralUtility;

class FileAllowedTypesValidator extends AbstractValidator
{
    /**
     * @var array
     */
    protected $supportedOptions = [
        'element' => ['', 'The name of the element', 'string', true],
        'errorMessage' => ['', 'The error message', 'array', true],
        'types' => ['', 'The allowed file types', 'string', true],
    ];

    /**
     * Constant for localisation
     *
     * @var string
     */
    const LOCALISATION_OBJECT_NAME = 'tx_form_system_validate_fileallowedtypes';

    /**
     * Check if the file mime type is allowed.
     *
     * The mime type is set in the propertymapper
     *
     * @see TYPO3\CMS\Form\Domain\Property\TypeConverter::convertFrom
     *
     * @param array $value
     * @return void
     */
    public function isValid($value)
    {
        $allowedTypes = strtolower($this->options['types']);
        $allowedMimeTypes = GeneralUtility::trimExplode(',', $allowedTypes, true);
        $fileMimeType = !empty($value['type']) ? strtolower($value['type']) : '';

        if (!in_array($fileMimeType, $allowedMimeTypes, true)) {
            $this->addError(
                $this->renderMessage(
                    $this->options['errorMessage'][0],
                    $this->options['errorMessage'][1],
                    'error'
                ),
                1442006702
            );
        }
    }

    /**
     * Substitute makers in the message text
     * Overrides the abstract
     *
     * @param string $message Message text with markers
     * @return string Message text with substituted markers
     */
    public function substituteMarkers($message)
    {
        $allowedTypes = strtolower($this->options['types']);
        $allowedMimeTypes = GeneralUtility::trimExplode(',', $allowedTypes);
        $allowedTypesStringForDisplay = implode(', ', $allowedMimeTypes);
        $message = str_replace('%allowedTypes', $allowedTypesStringForDisplay, $message);

        return $message;
    }
}


text:
angular.module('disc.lesson')
    .controller('LessonSearchCtrl', [
        '$scope',
        'LabelService',
        '$state',
        '$modal',
        function (
            $scope,
            LabelService,
            $state,
            $modal
            ) {
            //--------- Controller private methods ------
            _getLabel = function (label) {
                return LabelService.get('LessonSearchCtrl', label);
            }
            //--------- Controller public methods ------
            ///search
            ///@desc: change state to lessonSearch with keyword param (to preserve navigation history)
            ///old
            ///@desc: broadcast globally LessonSearchEvent with keyword in form input in 'lessonNews' or 'lessonSearch' state,
            ///        otherwise change state to lessonSearch with keyword param
            $scope.search = function () {
                // set inherit option to false to avoid conflict with parameters in URL set by advancedSearch
                $state.go('lessonSearch', { keyword: $scope.keyword }, { inherit: false });
                //$scope.viewAdvSearch = false;
                $scope.keyword = null;
                // If I don't want to preserve search/paging history navigation when the landing state is lessonSearch
                // I could use the following code, which doesn't change state transition (just event global broadcasting)
                /*
                if ($state.is('lessonNews') || $state.is('lessonSearch'))
                    $rootScope.$broadcast('LessonSearchEvent', { keyword: $scope.keyword })
                else
                    $state.go('lessonSearch', { keyword: $scope.keyword })
                */
            };

            $scope.openAdvSearch = function () {
                var modalInstance = $modal.open({
                    backdrop: true,
                    windowClass: 'modal',
                    templateUrl: 'LessonAdvSearch',
                    controller: 'LessonAdvSearchCtrl'
                });

                modalInstance.result.then(function (selectedItem) {
                    //$scope.selected = selectedItem;
                }, function () {
                    console.log('Modal dismissed at: ' + new Date());
                });
            }

            //--------- model initialization ------
            $scope.labels = {
                keywordPlaceholder: _getLabel('keywordPlaceholder'),
                searchButton: _getLabel('searchButton'),
                advancedSearchButton: _getLabel('advancedSearchButton')
            };
            $scope.keyword;
        }
    ]);


text:
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/common/utils/chipids.H $                     */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2018,2022                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/**
 * Contains constants for defined chip ids (aka. CFAM IDs, IDEC, etc)
 * for supported chips in POWER systems
 */

#ifndef _CHIPIDS_H
#define _CHIPIDS_H

#include <stdint.h>

// Standard chip ids
namespace POWER_CHIPID
{

/**
 * The format for all CFAM-based chips is:  MLmCC049
 *   M.m = Major.minor DD level, e.g. DD1.3
 *   L = Location
 *   CC = Unique chip id
 *
 * See https://eclipz.pok.ibm.com/sys/ras/docs/cfam_ids.txt
 */

/**
 * Extract the chipid from the full 32-bit CFAM ID
 * @param[in]  i_cfamId : 32-bit register data
 * @return 32-bit chipid value
 */
inline uint32_t extract_chipid32( uint32_t i_cfamId )
{
    return (i_cfamId & 0x0F0FF000);
};

/**
 * Extract the smaller chipid from the full 32-bit CFAM ID
 * @param[in]  i_cfamId : 32-bit register data
 * @return Left-justified 16-bit chipid value
 */
inline uint16_t extract_chipid16( uint32_t i_cfamId )
{
    return static_cast<uint16_t>((i_cfamId & 0x0F0FF000) >> 12);
};

/**
 * Extract the DD level from the full 32-bit CFAM ID
 * @param[in]  i_cfamId : 32-bit register data
 * @return Right-justified (1 byte) M.m DD level
 */
inline uint32_t extract_ddlevel( uint32_t i_cfamId )
{
    uint32_t l_major = 0xF0000000 & i_cfamId;
    uint32_t l_minor = 0x00F00000 & i_cfamId;
    return ((l_major >> 24) | (l_minor >> 20));
};

// Full 32-bit value with empty nibbles for DD level
constexpr uint32_t NIMBUS       = 0x020D1049;
constexpr uint32_t CUMULUS      = 0x020D4049;
constexpr uint32_t AXONE        = 0x020D9049;
constexpr uint32_t P10          = 0x020DA049;
constexpr uint32_t CENTAUR      = 0x06039049;
constexpr uint32_t EXPLORER     = 0x060D2000;
constexpr uint32_t GEMINI       = 0x060DC000;

// Shorter 16-bit value (drops Major nibble and 049)
constexpr uint32_t NIMBUS_16       = 0x20D1;
constexpr uint32_t CUMULUS_16      = 0x20D4;
constexpr uint32_t AXONE_16        = 0x20D9;
constexpr uint32_t P10_16          = 0x20DA;
constexpr uint32_t CENTAUR_16      = 0x6039;
constexpr uint32_t EXPLORER_16     = 0x60D2;
constexpr uint32_t GEMINI_16       = 0x60DC;

}; //namespace

// OpenCAPI ids
namespace POWER_OCID
{

// Device IDs
constexpr uint16_t EXPLORER     = 0x0636;
constexpr uint16_t ODYSSEY      = 0x06C3;

// Vendor IDs
constexpr uint16_t VENDOR_IBM   = 0x1014;

}; //namespace

// DMB (Differential Memory Buffer) IDs
namespace DDIMM_DMB_ID
{

// DDR4 DDIMM - Bytes [198][199]
constexpr uint16_t EXPLORER    = 0x8029;
constexpr uint16_t GEMINI      = 0x80A4;

};

#endif /* _CHIPIDS_H */


text:
using System;
using System.Collections.Generic;
using Lucene.Net.Index;
using Lucene.Net.Util;

namespace Lucene.Net.Spatial.Util
{
	/// <summary>
	/// Wraps Lucene 3 TermEnum to make it look like a Lucene 4 TermsEnum
	/// SOLR-2155
	/// @author dsmiley
	/// </summary>
	public class TermsEnumCompatibility
	{
		private readonly IndexReader reader;
		private readonly String fieldName;
		private TermEnum termEnum;
		private bool initialState = true;

		public TermsEnumCompatibility(IndexReader reader, String fieldName)
		{
			this.reader = reader;
			this.fieldName = string.Intern(fieldName);
			this.termEnum = reader.Terms(new Term(this.fieldName));
		}

		public TermEnum GetTermEnum()
		{
			return termEnum;
		}

		public Term Term()
		{
			Term t = termEnum.Term;
			return t != null && t.Field == fieldName ? t : null;
		}

		public Term Next()
		{
			//in Lucene 3, a call to reader.terms(term) is already pre-positioned, you don't call next first
			if (initialState)
			{
				initialState = false;
				return Term();
			}
			else
			{
				return termEnum.Next() ? Term() : null;
			}
		}

		public void Close()
		{
			termEnum.Close();
		}

		public enum SeekStatus
		{
			END,
			FOUND,
			NOT_FOUND
		}

		public SeekStatus Seek(String value)
		{
			termEnum = reader.Terms(new Term(this.fieldName, value));
			Term t = Term();
			if (t == null)
				return SeekStatus.END;
			return (t.Text.Equals(value)) ? SeekStatus.FOUND : SeekStatus.NOT_FOUND;
		}

		/// <summary>
		/// Seeks to the specified term, if it exists, or to the
		/// next (ceiling) term.  Returns SeekStatus to
		/// indicate whether exact term was found, a different
		/// term was found, or EOF was hit.  The target term may
		/// be before or after the current term.  If this returns
		/// SeekStatus.END, the enum is unpositioned.
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public SeekStatus SeekCeil(String value)
		{
			return Seek(value);
		}

		/// <summary>
		/// Returns the number of documents that have at least one
		/// term for this field, or -1 if this measure isn't
		/// stored by the codec.  Note that, just like other term
		/// measures, this measure does not take deleted documents
		/// into account.
		/// </summary>
		/// <returns></returns>
		public int GetDocCount()
		{
			return -1; // TODO find a way to efficiently determine this
		}

		public void Docs(OpenBitSet bits)
		{
			var termDocs = reader.TermDocs(new Term(fieldName, Term().Text));
			while (termDocs.Next())
			{
				bits.FastSet(termDocs.Doc);
			}
		}

		public void Docs(FixedBitSet bits)
		{
			var termDocs = reader.TermDocs(new Term(fieldName, Term().Text));
			while (termDocs.Next())
			{
				bits.Set(termDocs.Doc);
			}
		}
	}
}


text:
package com.cezarykluczynski.stapi.auth.oauth.github.service;

import com.cezarykluczynski.stapi.auth.oauth.github.configuration.GitHubOAuthProperties;
import org.springframework.stereotype.Service;

@Service
public class GitHubAdminDetector {

	private final GitHubOAuthProperties gitHubOAuthProperties;

	public GitHubAdminDetector(GitHubOAuthProperties gitHubOAuthProperties) {
		this.gitHubOAuthProperties = gitHubOAuthProperties;
	}

	public boolean isAdminId(Long id) {
		return gitHubOAuthProperties.getAdminIdentifiers().contains(id);
	}

}