Пример #1
0
        public static object GetTable(string name)
        {
            if (cache == null)
                cache = new Dictionary<string,object>();
            if (bits == null) {
                Stream unidata = Assembly.GetExecutingAssembly().
                    GetManifestResourceStream("unidata");
                bits = new byte[unidata.Length];
                unidata.Read(bits, 0, bits.Length);
                InflateDirectory();
                InflateAliases();
            }

            if (name != "" && name.Substring(0,1) != "!")
                name = StringProperty.Loosen(name);

            object r;
            string a;
            if (aliases.TryGetValue(name, out a))
                name = a;
            if (cache.TryGetValue(name, out r))
                return r;

            if (proxy_aliases.TryGetValue(name, out a))
                return cache[name] = ((LimitedProperty) GetTable(a)).Proxify(false, name);

            if (name == "ASSIGNED")
                return cache[name] = ((LimitedProperty) GetTable("gc"))
                    .Proxify(true, "+Cn");
            if (name == "ANY")
                return cache[name] = ((LimitedProperty) GetTable("gc"))
                    .Proxify(false, "+");
            if (name == "ASCII")
                return cache[name] = new LimitedProperty(
                    new int[] { 0, 1, 128, 0 },
                    new string[][] { LimitedProperty.NO, LimitedProperty.YES });

            if (name == "!inverse_name") {
                var inv = (GetTable("na") as StringProperty).MakeInverseMap();
                var na1 = GetTable("na1") as StringProperty;
                for (int i = 0; i < 32; i++)
                    inv[StringProperty.Loosen(na1.GetValue(i))] = i;
                for (int i = 128; i < 160; i++)
                    inv[StringProperty.Loosen(na1.GetValue(i))] = i;
                // semi-ad-hoc aliases used in spectests
                // UTS #28 2.5 recommends to add "aliases", but leaves
                // the specific aliases up to the regex impl ...
                inv["LF"] = 10;
                inv["CR"] = 13;
                inv["FF"] = 12;
                inv["NEL"] = 0x85;

                return cache[name] = inv;
            }

            int[] loc;
            if (!directory.TryGetValue(name, out loc))
                throw new NieczaException(name + " does not exist as a UCD table");

            switch (bits[loc[0]]) {
                case (byte)'B':
                    r = InflateBinary(name, loc);
                    break;
                case (byte)'E':
                    r = InflateEnum(name, loc);
                    break;
                case (byte)'N':
                    r = InflateName(name, loc);
                    break;
                case (byte)'S':
                    r = InflateString(name, loc);
                    break;
                default:
                    throw new NieczaException("Unhandled type code " + (char)bits[loc[0]]);
            }

            cache[name] = r;
            return r;
        }
Пример #2
0
        public static object GetTable(string name)
        {
            if (cache == null)
            {
                cache = new Dictionary <string, object>();
            }
            if (bits == null)
            {
                Stream unidata = Assembly.GetExecutingAssembly().
                                 GetManifestResourceStream("unidata");
                bits = new byte[unidata.Length];
                unidata.Read(bits, 0, bits.Length);
                InflateDirectory();
                InflateAliases();
            }

            if (name != "" && name.Substring(0, 1) != "!")
            {
                name = StringProperty.Loosen(name);
            }

            object r;
            string a;

            if (aliases.TryGetValue(name, out a))
            {
                name = a;
            }
            if (cache.TryGetValue(name, out r))
            {
                return(r);
            }

            if (proxy_aliases.TryGetValue(name, out a))
            {
                return(cache[name] = ((LimitedProperty)GetTable(a)).Proxify(false, name));
            }

            if (name == "ASSIGNED")
            {
                return(cache[name] = ((LimitedProperty)GetTable("gc"))
                                     .Proxify(true, "+Cn"));
            }
            if (name == "ANY")
            {
                return(cache[name] = ((LimitedProperty)GetTable("gc"))
                                     .Proxify(false, "+"));
            }
            if (name == "ASCII")
            {
                return(cache[name] = new LimitedProperty(
                           new int[] { 0, 1, 128, 0 },
                           new string[][] { LimitedProperty.NO, LimitedProperty.YES }));
            }

            if (name == "!inverse_name")
            {
                var inv = (GetTable("na") as StringProperty).MakeInverseMap();
                var na1 = GetTable("na1") as StringProperty;
                for (int i = 0; i < 32; i++)
                {
                    inv[StringProperty.Loosen(na1.GetValue(i))] = i;
                }
                for (int i = 128; i < 160; i++)
                {
                    inv[StringProperty.Loosen(na1.GetValue(i))] = i;
                }
                // semi-ad-hoc aliases used in spectests
                // UTS #28 2.5 recommends to add "aliases", but leaves
                // the specific aliases up to the regex impl ...
                inv["LF"]  = 10;
                inv["CR"]  = 13;
                inv["FF"]  = 12;
                inv["NEL"] = 0x85;

                return(cache[name] = inv);
            }

            int[] loc;
            if (!directory.TryGetValue(name, out loc))
            {
                throw new NieczaException(name + " does not exist as a UCD table");
            }

            switch (bits[loc[0]])
            {
            case (byte)'B':
                r = InflateBinary(name, loc);
                break;

            case (byte)'E':
                r = InflateEnum(name, loc);
                break;

            case (byte)'N':
                r = InflateName(name, loc);
                break;

            case (byte)'S':
                r = InflateString(name, loc);
                break;

            default:
                throw new NieczaException("Unhandled type code " + (char)bits[loc[0]]);
            }

            cache[name] = r;
            return(r);
        }