Beispiel #1
0
        internal Decoder SniffMeta()
        {
            int i = ReadChar();

            while (i != EOF)
            {
                char ch = (char)i;
                if (ch == '<')
                {
                    string name = SniffName();
                    if (name != null && StringUtilities.EqualsIgnoreCase(name, "meta"))
                    {
                        string httpequiv = null;
                        string content   = null;
                        while (true)
                        {
                            string value = SniffAttribute(out name);
                            if (name == null)
                            {
                                break;
                            }
                            if (StringUtilities.EqualsIgnoreCase(name, "http-equiv"))
                            {
                                httpequiv = value;
                            }
                            else if (StringUtilities.EqualsIgnoreCase(name, "content"))
                            {
                                content = value;
                            }
                        }
                        if (httpequiv != null && StringUtilities.EqualsIgnoreCase(httpequiv, "content-type") && content != null)
                        {
                            int j = content.IndexOf("charset");
                            if (j >= 0)
                            {
                                j = content.IndexOf("=", j);
                                if (j >= 0)
                                {
                                    j++;
                                    int k = content.IndexOf(";", j);
                                    if (k < 0)
                                    {
                                        k = content.Length;
                                    }
                                    string charset = content.Substring(j, k - j).Trim();
                                    try
                                    {
                                        Encoding e = Encoding.GetEncoding(charset);
                                        this.encoding = e;
                                        return(e.GetDecoder());
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                        }
                    }
                }
                i = ReadChar();
            }
            return(null);
        }