Пример #1
0
        TagTreeNode GetTagTree(string name)
        {
            var root = new TagTreeNode()
            {
                TagValue = "Root", TagName = "Root"
            };

            name = name.Replace('}', ']');
            name = name.Replace('{', '[');
            BuildTree(name, _body.First, root);
            return(root);
        }
Пример #2
0
        void BuildResults(TagTreeNode node, Dictionary <string, string> tagValues)
        {
            tagValues.Add(node.TagName, node.TagValue);

            foreach (var child in node.Childs)
            {
                BuildResults(child, new Dictionary <string, string>(tagValues));
            }

            if (node.Childs.Count == 0)
            {
                _posibleTagValues.Add(tagValues);
            }
        }
Пример #3
0
        void AddNewNode(string str, LinkedListNode <MaskItem> currentMaskItem, TagTreeNode currentTagTreeNode)
        {
            if (currentMaskItem.Next == null)
            {
                var newNode = new TagTreeNode()
                {
                    TagName = currentMaskItem.Value.Value, TagValue = str
                };
                currentTagTreeNode.AddChild(newNode);
                return;
            }

            var nextDelimiter      = currentMaskItem.Next.Value.Value;
            var currentTagName     = currentMaskItem.Value.Value;
            var nextDelimiterIndex = str.IndexOf(nextDelimiter);

            if (nextDelimiterIndex == -1)
            {
                return;
            }
            while (true)
            {
                var newNode = new TagTreeNode()
                {
                    TagName = currentTagName, TagValue = str.Substring(0, nextDelimiterIndex)
                };

                currentTagTreeNode.AddChild(newNode);
                BuildTree(str.Substring(nextDelimiterIndex, str.Length - newNode.TagValue.Length), currentMaskItem.Next, newNode);

                var strAfterNextDelimiter = str.Substring(nextDelimiterIndex + nextDelimiter.Length,
                                                          str.Length - nextDelimiter.Length - nextDelimiterIndex);
                if (nextDelimiter == "")
                {
                    nextDelimiterIndex++;
                    if (nextDelimiterIndex > str.Length)
                    {
                        return;
                    }
                }
                else if (ValidateString(strAfterNextDelimiter, currentMaskItem))
                {
                    nextDelimiterIndex = newNode.TagValue.Length + nextDelimiter.Length + strAfterNextDelimiter.IndexOf(nextDelimiter);
                }
                else
                {
                    return;
                }
            }
        }
Пример #4
0
        void BuildTree(string str, LinkedListNode <MaskItem> currentMaskItem, TagTreeNode currentTagTreeNode)
        {
            if (currentMaskItem == null)
            {
                return;
            }
            switch (currentMaskItem.Value.Type)
            {
            case MaskItemType.Delimiter:
                SkipDelimiter(str, currentMaskItem, currentTagTreeNode);
                break;

            case MaskItemType.TagName:
                AddNewNode(str, currentMaskItem, currentTagTreeNode);
                break;
            }
        }
Пример #5
0
 void SkipDelimiter(string str, LinkedListNode <MaskItem> currentMaskItem, TagTreeNode currentTagTreeNode)
 {
     BuildTree(str.Substring(currentMaskItem.Value.Value.Length), currentMaskItem.Next, currentTagTreeNode);
 }
Пример #6
0
 public void AddChild(TagTreeNode node)
 {
     node.Parent = this;
     Childs.Add(node);
 }
Пример #7
0
 public void AddChild(TagTreeNode node)
 {
     node.Parent = this;
     Childs.Add(node);
 }