private IEnumerable <INodeInfo> ExtractSubList(IEnumerable <INodeInfo> nodeInfos) { if (FTags.Count == 0) { return(nodeInfos); } else { var regex = new Regex(@"\[(.+)\]"); return(nodeInfos.Where((nodeInfo) => { var displayName = NodeInfoToDisplayName(nodeInfo); //bezier hack displayName = displayName.Replace('é', 'e'); //make all tags ToUpperFirst so they can be found var match = regex.Match(displayName); var upperedTags = match.Value.TrimStart('[').TrimEnd(']').Split(',').Select(x => x.Trim().ToUpperFirstInvariant()); displayName = regex.Replace(displayName, string.Join(", ", upperedTags)); var lowerDisplayName = displayName.ToLower(); bool containsAll = true; string t = ""; foreach (string tag in FTags) { t = tag.ToLower(); var found = false; if (FSwizzles.Contains(t)) { found = displayName.ToLower().Contains(t); } else if (FSingleCharNodes.Contains(t)) { found = displayName.ToLower().StartsWith(t); } else if (t.Length > 1) { t = t.ToUpperFirstInvariant(); //first char matches case-sensitive, all later chars match insensitive var pattern = "(" + Regex.Escape(t[0].ToString()) + "(?i)" + Regex.Escape(string.Join("", t.Skip(1))) + "(?-i))"; var rex = new Regex(pattern); var matches = rex.Match(displayName); found = matches.Length > 0; } else if (t.Length > 0) { found = displayName.IndexOf(t[0]) >= 0; } if (found) { if (!AndTags) { break; } } else { containsAll = false; } if ((AndTags) && (!containsAll)) { break; } } //todo: remove OR-tags case or refine it if (((AndTags) && (containsAll)) || ((!AndTags) && (lowerDisplayName.Contains(t.ToLower())))) { return true; } else { return false; } })); } }
private IEnumerable <INodeInfo> ExtractSubList(IEnumerable <INodeInfo> nodeInfos) { if (FTags.Count == 0) { return(nodeInfos); } else { var regex = new Regex(@"\[(.+)\]"); return(nodeInfos.Where((nodeInfo) => { var displayName = NodeInfoToDisplayName(nodeInfo); //bezier hack displayName = displayName.Replace('é', 'e'); //make all tags ToUpperFirst so they can be found var match = regex.Match(displayName); var upperedTags = match.Value.TrimStart('[').TrimEnd(']').Split(',').Select(x => x.Trim().ToUpperFirstInvariant()); displayName = regex.Replace(displayName, string.Join(", ", upperedTags)); var lowerDisplayName = displayName.ToLower(); bool containsAll = true; string t = ""; foreach (string tag in FTags) { t = tag.ToLower(); var found = false; if (FSwizzles.Contains(t)) { found = displayName.ToLower().Contains(t); } if (!found && FSingleCharNodes.Contains(t)) { found = displayName.ToLower().StartsWith(t); } if (!found) { //first we check case-insensitive if the displayname simply start with the given tag found = displayName.ToLower().StartsWith(t); if (!found) { //then we consider the tag a sub-term in the displayname //and therefore want it to start with a capital letter //so that we don't just find any occurances //but only those were the tag appears as a proper camel-cased sub-term t = t.ToUpperFirstInvariant(); //first char matches case-sensitive, all later chars match insensitive var pattern = "(" + Regex.Escape(t[0].ToString()) + "(?i)" + Regex.Escape(string.Join("", t.Skip(1))) + "(?-i))"; var rex = new Regex(pattern); var matches = rex.Match(displayName); found = matches.Length > 0; } } if (found) { if (!AndTags) { break; } } else { containsAll = false; } if ((AndTags) && (!containsAll)) { break; } } //todo: remove OR-tags case or refine it if (((AndTags) && (containsAll)) || ((!AndTags) && (lowerDisplayName.Contains(t.ToLower())))) { return true; } else { return false; } })); } }