private Node[] FindAll(string pattern, FindBundle bundle) { List <Node> ret = new List <Node>(); FindAll(pattern, ret, bundle); return(ret.ToArray()); }
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); }
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); }
private bool Match(string pattern, FindBundle bundle = null) { // if not pattern match, just compare key if (bundle == null) { return(Key == pattern); } return(Match(bundle)); }
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); }
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()); }
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); } }