コード例 #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);
        }
コード例 #2
0
        /// <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
ファイル: TmxNode.cs プロジェクト: GeeBook/DocumentTranslator
 /// <summary>
 /// Initializes a new instance of the TmxNode class.
 /// </summary>
 protected TmxNode()
 {
     this.parent = null;
 }
コード例 #6
0
ファイル: TmxNode.cs プロジェクト: GeeBook/DocumentTranslator
 /// <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
ファイル: TmxNode.cs プロジェクト: GeeBook/DocumentTranslator
        /// <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;
        }
コード例 #8
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;
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the TmxAttributeCollection class.
 /// </summary>
 public TmxAttributeCollection()
 {
     this.element = null;
 }
コード例 #10
0
        /*
         * 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);
        }
コード例 #11
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;
 }
コード例 #12
0
 /// <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;
 }