private static ITestEntry CreateTestEntry(string value, bool wholeMatch, bool strictMode) { if (value.Length > 1) { if (value[0] == '"' && value[value.Length - 1] == '"') { return(new StringTestEntry(value.Substring(1, value.Length - 2), wholeMatch, true)); } if (value[0] == '`' && value[value.Length - 1] == '`') { try { var regex = new Regex(value.Substring(1, value.Length - 2), RegexOptions.Compiled | RegexOptions.IgnoreCase); return(new RegexTestEntry(regex)); } catch (Exception) { return(new ConstTestEntry(false)); } } } if (value.Contains("*") || value.Contains("?")) { return(new RegexTestEntry(RegexFromQuery.Create(value, wholeMatch, strictMode))); } return(new StringTestEntry(value, wholeMatch, strictMode)); }
public IEnumerable <string> GetKeys(string glob) { if (_originFilename == null) { return(new string[0]); } if (_dataList == null) { var directory = _originFilename; var dataList = new List <string>(); if (Directory.Exists(directory)) { dataList.AddRange(Directory.GetFiles(directory, "*", SearchOption.AllDirectories)); for (var i = 0; i < dataList.Count; i++) { dataList[i] = FileUtils.GetRelativePath(dataList[i], directory).Replace('\\', '/'); } var fromArchive = GetDataArchive()?.Entries.Select(x => x.FullName); if (fromArchive != null) { dataList.AddRange(fromArchive); } } _dataList = dataList.ToArray(); } var regex = RegexFromQuery.Create(glob, StringMatchMode.CompleteMatch); return(_dataList.Where(x => regex.IsMatch(x))); }
private static PaintableItem FindQuery([NotNull] Kn5 kn5, Func <string, PaintableItem> prepare, params string[] query) { var texture = query.Select(x => RegexFromQuery.IsQuery(x) ? kn5.Textures.Keys.FirstOrDefault(RegexFromQuery.Create(x, StringMatchMode.CompleteMatch, false).IsMatch) : kn5.Textures.Keys.Contains(x) ? x : null).FirstOrDefault(x => x != null); return(texture != null?prepare(texture) : null); }
private IEnumerable <string> GetFiles(string mask) { var location = _current.Location; if (_subFiles == null) { _subFiles = Directory.GetFiles(location, "*", SearchOption.AllDirectories) .Select(x => FileUtils.GetRelativePath(x, location)).ToArray(); } var f = RegexFromQuery.Create(mask.Replace('/', '\\'), true, true); return(_subFiles.Where(x => f.IsMatch(x)).Select(x => Path.Combine(location, x))); }