⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entity.cs

📁 Freetextbox是优秀的在线编辑器
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace FreeTextBoxControls.Support.Sgml
{
    using System;
    using System.IO;
    using System.Net;
    using System.Text;

    public class Entity
    {
        static Entity()
        {
            Entity.CtrlMap = new int[] { 
                0x20ac, 0x81, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 710, 0x2030, 0x160, 0x2039, 0x152, 0x8d, 0x17d, 0x8f, 
                0x90, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x2dc, 0x2122, 0x161, 0x203a, 0x153, 0x9d, 0x17e, 0x178
             };
        }

        public Entity(string name, string literal)
        {
            this.Name = name;
            this.Literal = literal;
            this.Internal = true;
        }

        public Entity(string name, string pubid, string uri, string proxy)
        {
            this.Name = name;
            this.PublicId = pubid;
            this.Uri = uri;
            this.Proxy = proxy;
            this.Html = (name != null) && (name.ToLower() == "html");
        }

        public Entity(string name, System.Uri baseUri, TextReader stm, string proxy)
        {
            this.Name = name;
            this.Internal = true;
            this.stm = stm;
            this.resolvedUri = baseUri;
            this.Proxy = proxy;
            this.Html = name.ToLower() == "html";
        }

        public void Close()
        {
            if (this.weOwnTheStream)
            {
                this.stm.Close();
            }
        }

        public string Context()
        {
            Entity entity1 = this;
            StringBuilder builder1 = new StringBuilder();
            while (entity1 != null)
            {
                string text1;
                if (entity1.Internal)
                {
                    text1 = string.Format("\nReferenced on line {0}, position {1} of internal entity '{2}'", entity1.Line, entity1.LinePosition, entity1.Name);
                }
                else
                {
                    text1 = string.Format("\nReferenced on line {0}, position {1} of '{2}' entity at [{3}]", new object[] { entity1.Line, entity1.LinePosition, entity1.Name, entity1.ResolvedUri.AbsolutePath });
                }
                builder1.Append(text1);
                entity1 = entity1.Parent;
            }
            return builder1.ToString();
        }

        public void Error(string msg)
        {
            throw new Exception(msg);
        }

        public void Error(string msg, char ch)
        {
            string text1 = (ch == 0xffff) ? "EOF" : char.ToString(ch);
            throw new Exception(string.Format(msg, text1));
        }

        public void Error(string msg, int x)
        {
            throw new Exception(string.Format(msg, x));
        }

        public void Error(string msg, string arg)
        {
            throw new Exception(string.Format(msg, arg));
        }

        public string ExpandCharEntity()
        {
            char ch1 = this.ReadChar();
            int num1 = 0;
            if (ch1 != 'x')
            {
                while ((ch1 != 0xffff) && (ch1 != ';'))
                {
                    if ((ch1 >= '0') && (ch1 <= '9'))
                    {
                        num1 = (num1 * 10) + (ch1 - '0');
                    }
                    else
                    {
                        break;
                    }
                    ch1 = this.ReadChar();
                }
            }
            else
            {
                while ((ch1 != 0xffff) && (ch1 != ';'))
                {
                    int num2 = 0;
                    if ((ch1 >= '0') && (ch1 <= '9'))
                    {
                        num2 = ch1 - '0';
                    }
                    else if ((ch1 >= 'a') && (ch1 <= 'f'))
                    {
                        num2 = (ch1 - 'a') + '\n';
                    }
                    else if ((ch1 >= 'A') && (ch1 <= 'F'))
                    {
                        num2 = (ch1 - 'A') + '\n';
                    }
                    else
                    {
                        break;
                    }
                    num1 = (num1 * 0x10) + num2;
                    ch1 = this.ReadChar();
                }
            }
            if (ch1 == '\0')
            {
                this.Error("Premature {0} parsing entity reference", ch1);
            }
            if (this.Html && ((num1 >= 0x80) & (num1 <= 0x9f)))
            {
                int num3 = Entity.CtrlMap.Length;
                int num4 = num1 - 0x80;
                int num5 = Entity.CtrlMap[num4];
                return Convert.ToChar(num5).ToString();
            }
            return Convert.ToChar(num1).ToString();
        }

        public Encoding GetEncoding()
        {
            return this.encoding;
        }

        public static bool IsLiteralType(string token)
        {
            return (((token == "CDATA") || (token == "SDATA")) || (token == "PI"));
        }

        public void Open(Entity parent, System.Uri baseUri)
        {
            this.Parent = parent;
            if (parent != null)
            {
                this.Html = parent.Html;
            }
            this.Line = 1;
            if (this.Internal)
            {
                if (this.Literal != null)
                {
                    this.stm = new StringReader(this.Literal);
                }
            }
            else if (this.Uri == null)
            {
                this.Error("Unresolvable entity '{0}'", this.Name);
            }
            else
            {
                if (baseUri != null)
                {
                    this.resolvedUri = new System.Uri(baseUri, this.Uri);
                }
                else
                {
                    this.resolvedUri = new System.Uri(this.Uri);
                }
                Stream stream1 = null;
                Encoding encoding1 = Encoding.Default;
                string text4 = this.resolvedUri.Scheme;
                if ((text4 != null) && (text4 == "file"))
                {
                    stream1 = new FileStream(this.resolvedUri.LocalPath, FileMode.Open, FileAccess.Read);
                }
                else
                {
                    HttpWebRequest request1 = (HttpWebRequest) WebRequest.Create(this.ResolvedUri);
                    request1.UserAgent = "Mozilla/4.0 (compatible;);";
                    request1.Timeout = 0x2710;
                    if (this.Proxy != null)
                    {
                        request1.Proxy = new WebProxy(this.Proxy);
                    }
                    request1.PreAuthenticate = false;
                    request1.Credentials = CredentialCache.DefaultCredentials;
                    WebResponse response1 = request1.GetResponse();
                    System.Uri uri1 = response1.ResponseUri;
                    if (uri1.AbsoluteUri != this.resolvedUri.AbsoluteUri)
                    {
                        this.resolvedUri = uri1;
                    }
                    string text2 = response1.ContentType.ToLower();
                    int num1 = text2.IndexOf("charset");
                    encoding1 = Encoding.Default;
                    if (num1 >= 0)
                    {
                        int num2 = text2.IndexOf("=", num1);
                        int num3 = text2.IndexOf(";", num2);
                        if (num3 < 0)
                        {
                            num3 = text2.Length;
                        }
                        if (num2 > 0)
                        {
                            num2++;
                            string text3 = text2.Substring(num2, num3 - num2).Trim();
                            try
                            {
                                encoding1 = Encoding.GetEncoding(text3);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    stream1 = response1.GetResponseStream();
                }
                this.weOwnTheStream = true;
                HtmlStream stream2 = new HtmlStream(stream1, encoding1);
                this.encoding = stream2.Encoding;
                this.stm = stream2;
            }
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -