示例#1
0
        private Node[] FindAll(string pattern, FindBundle bundle)
        {
            List <Node> ret = new List <Node>();

            FindAll(pattern, ret, bundle);
            return(ret.ToArray());
        }
示例#2
0
        private Node Find(string pattern, FindBundle bundle)
        {
            if (Match(pattern, bundle))
            {
                return(this);
            }
            Node found = null;

            foreach (Node attri in Attributes)
            {
                found = attri.Find(pattern, bundle);
                if (found != null)
                {
                    return(found);
                }
            }
            foreach (Node child in Children)
            {
                found = child.Find(pattern, bundle);
                if (found != null)
                {
                    return(found);
                }
            }
            return(found);
        }
示例#3
0
        private FindBundle MakeFindBundle(string pattern, bool ispattern = true)
        {
            if (ispattern == false)
            {
                return(null);
            }

            pattern += '^';

            string        keyValue = "";
            List <string> attributes = new List <string>(), children = new List <string>();
            string        tempStr     = "";
            int           patternType = 0;

            foreach (char c in pattern)
            {
                if (c == '@' || c == ':' || c == ',' || c == ' ' || c == '^')
                {
                    if (tempStr != "")
                    {
                        if (patternType == 0)
                        {
                            keyValue = tempStr;
                        }
                        else if (patternType == 1)
                        {
                            attributes.Add(tempStr);
                        }
                        else
                        {
                            children.Add(tempStr);
                        }
                    }
                    tempStr = "";
                    if (c == '@')
                    {
                        patternType = 1;
                    }
                    else if (c == ':')
                    {
                        patternType = 2;
                    }
                }
                else
                {
                    tempStr += c;
                }
            }

            FindBundle bundle = new FindBundle();

            bundle.keyValue   = keyValue;
            bundle.attributes = attributes;
            bundle.children   = children;

            return(bundle);
        }
示例#4
0
        private bool Match(string pattern, FindBundle bundle = null)
        {
            // if not pattern match, just compare key
            if (bundle == null)
            {
                return(Key == pattern);
            }

            return(Match(bundle));
        }
示例#5
0
        private bool Match(FindBundle bundle)
        {
            if (bundle.keyValue != "")
            {
                if (!MatchKeyValuePair(bundle.keyValue))
                {
                    return(false);
                }
            }

            if (bundle.attributes.Count > 0)
            {
                List <string> matches = bundle.attributes.ToList();
                foreach (Node node in Attributes)
                {
                    foreach (string match in matches)
                    {
                        if (node.MatchKeyValuePair(match))
                        {
                            matches.Remove(match);
                            break;
                        }
                    }
                }
                if (matches.Count > 0)
                {
                    return(false);
                }
            }

            if (bundle.children.Count > 0)
            {
                List <string> matches = bundle.children.ToList();
                foreach (Node node in Children)
                {
                    foreach (string match in matches)
                    {
                        if (node.MatchKeyValuePair(match))
                        {
                            matches.Remove(match);
                            break;
                        }
                    }
                }
                if (matches.Count > 0)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#6
0
        private Node[] FindChild(string pattern, FindBundle bundle)
        {
            List <Node> ret_list = new List <Node>();

            foreach (Node child in Children)
            {
                if (child.Match(pattern, bundle))
                {
                    ret_list.Add(child);
                }
            }
            return(ret_list.ToArray());
        }
示例#7
0
 private void FindAll(string pattern, List <Node> ret_list, FindBundle bundle)
 {
     if (Match(pattern, bundle))
     {
         ret_list.Add(this);
     }
     foreach (Node attri in Attributes)
     {
         attri.FindAll(pattern, ret_list, bundle);
     }
     foreach (Node child in Children)
     {
         child.FindAll(pattern, ret_list, bundle);
     }
 }