Esempio n. 1
0
        protected bool Equals(TagAttributeCollection other)
        {
            if (other == null)
            {
                return(false);
            }

            if (Count != other.Count)
            {
                return(false);
            }

            for (int i = 0; i < Count; i++)
            {
                if (!EqualityComparer <TagAttribute> .Default.Equals(this[i], other[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
 internal OpeningTag(string syntaxText, string tagText, string name, TagAttributeCollection attributes) : base(syntaxText, tagText)
 {
     Name        = name;
     _attributes = attributes;
 }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="syntaxText">Text from '&lt;' to '&gt;'</param>
        /// <returns></returns>
        internal OpeningTag ParseOpeningTag(string syntaxText)
        {
            var tagText = syntaxText.Substring(1, syntaxText.Length - 2);

            var c = tagText[0];

            if (tagText.Length == 1)
            {
                switch (c)
                {
                case '/':
                    throw new XmlAnalysisException();
                }
            }

            var nameLength                    = 0;
            var isName                        = true;
            var attributeStartIndex           = 0;
            var attributeLength               = 0;
            List <TagAttribute> attributeList = new List <TagAttribute>();

            for (var i = 0; i < tagText.Length; i++)
            {
                c = tagText[i];
                switch (c)
                {
                case '/':
                    throw new XmlAnalysisException();

                case ' ':
                    isName = false;
                    if (attributeLength != 0)
                    {
                        attributeList.Add(ConvertTo(tagText.Substring(attributeStartIndex, attributeLength)));
                        attributeLength = 0;
                    }
                    continue;
                }

                if (isName)
                {
                    nameLength++;
                }
                else
                {
                    if (attributeLength == 0)
                    {
                        attributeStartIndex = i;
                    }
                    attributeLength++;
                }
            }

            if (attributeLength != 0)
            {
                attributeList.Add(ConvertTo(tagText.Substring(attributeStartIndex, attributeLength)));
            }

            var first  = tagText[0];
            var latest = tagText[tagText.Length - 1];

            if (first == '/' && latest == '/')
            {
                throw new XmlAnalysisException();
            }

            if (first == '/')
            {
                throw new XmlAnalysisException();
            }

            string name       = tagText.Length == nameLength ? tagText : tagText.Substring(0, nameLength);
            var    attributes = new TagAttributeCollection(attributeList);

            return(new OpeningTag(syntaxText, tagText, name, attributes));
        }