Beispiel #1
0
        public void Parse(string html, int location)
        {
            TextProcess proc = new TextProcess();

            parseProperties(html, proc, location);
            int end = 0;

            for (int i = this.location + 1; i < html.Length; i++)
            {
                if (html[i] == '<')
                {
                    if (html[i + 1] == '/')
                    {
                        end = html.IndexOf('>', i + 1);
                        string name = proc.Cut(html, i + 2, end - 1);
                        if (TagName == name)
                        {
                            TagClosed = true;

                            location = end;

                            break;
                        }
                    }
                    else
                    {
                        tags.Add(new HtmlTag(html, i, this));
                        i = tags[tags.Count - 1].location;
                        continue;
                    }
                }
            }
        }
Beispiel #2
0
        void parseProperties(string html, TextProcess proc, int loc)
        {
            StringBuilder builder       = new StringBuilder();
            int           end           = 0;
            string        propertyValue = "";
            string        propertyName  = "";
            int           mode          = 0;

            for (int i = loc; i < html.Length; i++)
            {
                if (html[i] == '"' || html[i] == '\'')
                {
                    end           = html.IndexOf(html[i], i + 1);
                    propertyValue = proc.Cut(html, i + 1, end - 1);

                    i = end;
                    if (properties.ContainsKey(propertyName) == false)
                    {
                        properties.Add(propertyName, propertyValue);
                        builder.Clear();
                    }
                    continue;
                }
                if (html[i] == '>')
                {
                    location = i;

                    break;
                }
                if (html[i] == '=')
                {
                    if (mode == 0)
                    {
                        propertyName = builder.ToString();
                        builder.Clear();

                        mode = 1;
                        continue;
                    }
                }
                if (mode == 1 && char.IsWhiteSpace(html[i]) == true)
                {
                    if (properties.ContainsKey(propertyName) == false)
                    {
                        properties.Add(propertyName, builder.ToString());
                        builder.Clear();
                    }
                    mode = 0;
                }
                if (mode == 0)
                {
                    if (char.IsWhiteSpace(html[i]) == false)
                    {
                        builder.Append(html[i]);
                    }
                }
                else
                {
                    builder.Append(html[i]);
                }
            }
        }