Пример #1
0
        /// <summary>
        /// This will return true if the node passed is a descendent of this node.
        /// </summary>
        /// <param name="node">The node that might be the parent or grandparent (etc).</param>
        /// <returns>True if this node is a descendent of the one passed in.</returns>
        public bool IsDescendentOf(TmxNode node)
        {
            TmxNode parent = this.Parent;

            while (parent != null)
            {
                if (parent == node)
                {
                    return(true);
                }

                parent = parent.Parent;
            }

            return(false);
        }
        /// <summary>
        /// This will move all the nodes from the specified index to the new parent.
        /// </summary>
        /// <param name="nodes">The collection of nodes.</param>
        /// <param name="node_index">The index of the first node (in the above collection) to move.</param>
        /// <param name="new_parent">The node which will become the parent of the moved nodes.</param>
        private void MoveNodesDown(ref TmxNodeCollection nodes, int node_index, TmxElement new_parent)
        {
            for (int i = node_index; i < nodes.Count; i++)
            {
                ((TmxElement)new_parent).Nodes.Add(nodes[i]);
                nodes[i].SetParent(new_parent);
            }

            int c = nodes.Count;

            for (int i = node_index; i < c; i++)
            {
                nodes.RemoveAt(node_index);
            }

            new_parent.IsExplicitlyTerminated = true;
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the TmxAttributeCollection class.
 /// </summary>
 /// <param name="element">Specifies an element.</param>
 internal TmxAttributeCollection(TmxElement element)
 {
     this.element = element;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the TmxAttributeCollection class.
 /// </summary>
 public TmxAttributeCollection()
 {
     this.element = null;
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the TmxNode class.
 /// </summary>
 protected TmxNode()
 {
     this.parent = null;
 }
Пример #6
0
 /// <summary>
 /// Internal method to maintain the identity of the parent node.
 /// </summary>
 /// <param name="parentNode">The parent node of this one.</param>
 internal void SetParent(TmxElement parentNode)
 {
     this.parent = parentNode;
 }
Пример #7
0
        /// <summary>
        /// This will return true if the node passed is a descendent of this node.
        /// </summary>
        /// <param name="node">The node that might be the parent or grandparent (etc).</param>
        /// <returns>True if this node is a descendent of the one passed in.</returns>
        public bool IsDescendentOf(TmxNode node)
        {
            TmxNode parent = this.Parent;
            while (parent != null)
            {
                if (parent == node)
                {
                    return true;
                }

                parent = parent.Parent;
            }

            return false;
        }
 /// <summary>
 /// Initializes a new instance of the TmxAttributeCollection class.
 /// </summary>
 /// <param name="element">Specifies an element.</param>
 internal TmxAttributeCollection(TmxElement element)
 {
     this.element = element;
 }
 /// <summary>
 /// Initializes a new instance of the TmxAttributeCollection class.
 /// </summary>
 public TmxAttributeCollection()
 {
     this.element = null;
 }
        /*
         * This method contains valid code. Commented for code coverage purpose.
         *
         * /// <summary>
         * /// This will parse a string containing HTML and will produce a domain tree.
         * /// </summary>
         * /// <param name="html">The HTML to be parsed.</param>
         * /// <returns>A tree representing the elements.</returns>
         * public TmxNodeCollection Parse(string html)
         * {
         *  return this.Parse(html, false);
         * }
         */

        public TmxNodeCollection Parse(string html, bool addLineBreaks)
        {
            TmxNodeCollection nodes = new TmxNodeCollection(null);

            html = this.PreprocessScript(html, Token.SCRIPT);
            html = this.PreprocessScript(html, Token.STYLE);

            html = this.RemoveComments(html);

            StringCollection tokens = this.GetTokens(html);

            int        index   = 0;
            TmxElement element = null;

            while (index < tokens.Count)
            {
                if (Str.IsLT(tokens[index]))
                {
                    // Read open tag
                    index++;
                    if (index >= tokens.Count)
                    {
                        break;
                    }

                    string tag_name = tokens[index];
                    index++;
                    element = new TmxElement(tag_name);

                    if (addLineBreaks)
                    {
                        element.AddLineBreaks = true;
                    }

                    // Read the attributes and values.
                    while (index < tokens.Count && !Str.IsGT(tokens[index]) && !Str.IsSLGT(tokens[index]))
                    {
                        string attribute_name = tokens[index];
                        index++;

                        if (index < tokens.Count && Str.IsEQ(tokens[index]))
                        {
                            index++;
                            string attribute_value;
                            if (index < tokens.Count)
                            {
                                attribute_value = tokens[index];
                            }
                            else
                            {
                                attribute_value = null;
                            }

                            index++;

                            TmxAttribute attribute = new TmxAttribute(attribute_name, attribute_value);
                            element.Attributes.Add(attribute);
                        }
                        else if (index < tokens.Count)
                        {
                            // Null-value attribute
                            TmxAttribute attribute = new TmxAttribute(attribute_name, null);
                            element.Attributes.Add(attribute);
                        }
                    }

                    nodes.Add(element);
                    if (index < tokens.Count && Str.IsSLGT(tokens[index]))
                    {
                        element.IsTerminated = true;
                        index++;
                        element = null;
                    }
                    else if (index < tokens.Count && Str.IsGT(tokens[index]))
                    {
                        index++;
                    }
                }
                else if (Str.IsGT(tokens[index]))
                {
                    index++;
                }
                else if (Str.IsLTSL(tokens[index]))
                {
                    // Read close tag
                    index++;
                    if (index >= tokens.Count)
                    {
                        break;
                    }

                    string tag_name = tokens[index];
                    index++;

                    int open_index = this.FindTagOpenNodeIndex(nodes, tag_name);
                    if (open_index != -1)
                    {
                        this.MoveNodesDown(ref nodes, open_index + 1, (TmxElement)nodes[open_index]);
                    }
                    else
                    {
                        // Er, there is a close tag without an opening tag!!
                    }

                    // Skip to the end of this tag
                    while (index < tokens.Count && !Str.IsGT(tokens[index]))
                    {
                        index++;
                    }

                    if (index < tokens.Count && Str.IsGT(tokens[index]))
                    {
                        index++;
                    }

                    element = null;
                }
                else
                {
                    // Read text
                    string value = tokens[index];

                    if (this.isRemoveEmptyElementText)
                    {
                        value = this.RemoveWhitespace(value);
                    }

                    value = DecodeScript(value);

                    if (this.isRemoveEmptyElementText && value.Length == 0)
                    {
                        // We do nothing
                    }
                    else
                    {
                        TmxText node = new TmxText(value);
                        nodes.Add(node);
                    }

                    index++;
                }
            }

            return(nodes);
        }
 /// <summary>
 /// Initializes a new instance of the TmxNodeCollection class.
 /// A collection is usually associated with a parent node (an HtmlElement, actually)
 /// but you can pass null to implement an abstracted collection.
 /// </summary>
 /// <param name="parent">The parent element, or null if it is not appropriate.</param>
 internal TmxNodeCollection(TmxElement parent)
 {
     this.parent = parent;
 }
 /// <summary>
 /// Initializes a new instance of the TmxNodeCollection class.
 /// </summary>
 public TmxNodeCollection()
 {
     this.parent = null;
 }
Пример #13
0
 /// <summary>
 /// Initializes a new instance of the TmxNodeCollection class.
 /// A collection is usually associated with a parent node (an HtmlElement, actually)
 /// but you can pass null to implement an abstracted collection.
 /// </summary>
 /// <param name="parent">The parent element, or null if it is not appropriate.</param>
 internal TmxNodeCollection(TmxElement parent)
 {
     this.parent = parent;
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the TmxNodeCollection class.
 /// </summary>
 public TmxNodeCollection()
 {
     this.parent = null;
 }
Пример #15
0
 /// <summary>
 /// Internal method to maintain the identity of the parent node.
 /// </summary>
 /// <param name="parentNode">The parent node of this one.</param>
 internal void SetParent(TmxElement parentNode)
 {
     this.parent = parentNode;
 }
Пример #16
0
 /// <summary>
 /// Initializes a new instance of the TmxNode class.
 /// </summary>
 protected TmxNode()
 {
     this.parent = null;
 }