using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using Time = System.Double; namespace ProfileEventViewer { public class Filters { public string OriginalFilter { get; set; } private List m_Filters = new List(); public bool IsValid { get { return m_Filters.Count != 0; } } public Filters() { SetFilter(string.Empty); } public void SetFilter(string filter) { m_Filters.Clear(); m_Filters.AddRange(ParseFilter(filter).Select(f => f.ToUpperInvariant())); OriginalFilter = filter; } private IEnumerable ParseFilter(string filter) { int lastIndex = 0; bool inQuotes = false; for (int index = 0; index < filter.Length; ++index) { char c = filter[index]; if (c == '"') { if (lastIndex < index - 1) { string substr = filter.Substring(lastIndex, index - lastIndex); if (inQuotes) yield return substr; else foreach (string subFilter in substr.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)) yield return subFilter; } lastIndex = index + 1; inQuotes = !inQuotes; } } if (lastIndex != filter.Length) { string substr = filter.Substring(lastIndex, filter.Length - lastIndex); if (inQuotes) yield return substr; else foreach (string subFilter in substr.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)) yield return subFilter; } } public bool IsAllowed(string str) { string upperStr = str.ToUpperInvariant(); return m_Filters.Any(filter => upperStr.Contains(filter)); } } public class ClockTime { private List m_TimeExtents = new List(); private List