Exemple #1
0
        public static void Load(this Hashtable props, System.IO.Stream stream)
        {
            if (stream == null)
            {
                return;
            }
            using (var reader = new InputStreamReader((InputStream)stream, Encoding.UTF8))
            {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    if (!String.IsNullOrWhiteSpace(line) && !line.StartsWith("#"))
                    {
                        var parts = line.Split('=');
                        if (parts.Length != 2)
                        {
                            throw new InvalidOperationException("Properties must be key value pairs separated by an '='.");
                        }

                        if (!props.ContainsKey(parts[0]))
                        {
                            props.Add(parts[0], parts[1]);
                        }
                        else
                        {
                            props[parts[0]] = parts[1];
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Loads the CharHandlers for the given range of characters from the
        /// resource file with the given name.
        /// </summary>
        /// <remarks>
        /// Loads the CharHandlers for the given range of characters from the
        /// resource file with the given name.
        /// </remarks>
        internal static GeneralLegacyIndexCodes.CharHandler[] LoadCodes(string codesFilePath
                                                                        , char firstChar, char lastChar)
        {
            int numCodes = (AsUnsignedChar(lastChar) - AsUnsignedChar(firstChar)) + 1;

            GeneralLegacyIndexCodes.CharHandler[] values = new GeneralLegacyIndexCodes.CharHandler
                                                           [numCodes];
            IDictionary <string, GeneralLegacyIndexCodes.Type> prefixMap = new Dictionary <string
                                                                                           , GeneralLegacyIndexCodes.Type>();

            prefixMap.Put("S", GeneralLegacyIndexCodes.Type.SIMPLE);
            prefixMap.Put("I", GeneralLegacyIndexCodes.Type.INTERNATIONAL);
            prefixMap.Put("U", GeneralLegacyIndexCodes.Type.UNPRINTABLE);
            prefixMap.Put("P", GeneralLegacyIndexCodes.Type.UNPRINTABLE_EXT);
            prefixMap.Put("Z", GeneralLegacyIndexCodes.Type.INTERNATIONAL_EXT);
            prefixMap.Put("X", GeneralLegacyIndexCodes.Type.IGNORED);

            InputStreamReader reader = null;

            try
            {
                reader = new InputStreamReader(Database.GetResourceAsStream(codesFilePath
                                                                            ), "US-ASCII");
                int start = AsUnsignedChar(firstChar);
                int end   = AsUnsignedChar(lastChar);
                for (int i = start; i <= end; ++i)
                {
                    char c = (char)i;
                    GeneralLegacyIndexCodes.CharHandler ch = null;
                    if (char.IsHighSurrogate(c) || char.IsLowSurrogate(c))
                    {
                        // surrogate chars are not included in the codes files
                        ch = SURROGATE_CHAR_HANDLER;
                    }
                    else
                    {
                        string codeLine = reader.ReadLine();
                        ch = ParseCodes(prefixMap, codeLine);
                    }
                    values[(i - start)] = ch;
                }
            }
            catch (IOException e)
            {
                throw new RuntimeException("failed loading index codes file " + codesFilePath, e);
            }
            finally
            {
                if (reader != null)
                {
                    try
                    {
                        reader.Close();
                    }
                    catch (IOException)
                    {
                    }
                }
            }
            // ignored
            return(values);
        }