Example #1
0
        /// <summary>
        /// Returns all boundaries matching the pattern in a text
        /// </summary>
        /// <param name="pattern">Search pattern</param>
        /// <param name="text">Text</param>
        /// <returns>List of boundaries</returns>
        private List <Boundary> MatchPattern(SearchPattern pattern, string text)
        {
            List <Boundary> matchList = new List <Boundary>();

            RegexOptions reopt = RegexOptions.None;

            if (pattern.Modifiers != null && pattern.Modifiers.Length > 0)
            {
                reopt |= (pattern.Modifiers.Contains("i")) ? RegexOptions.IgnoreCase : RegexOptions.None;
                reopt |= (pattern.Modifiers.Contains("m")) ? RegexOptions.Multiline : RegexOptions.None;
            }

            Regex           patRegx = new Regex(pattern.Pattern, reopt);
            MatchCollection matches = patRegx.Matches(text);

            if (matches.Count > 0)
            {
                foreach (Match?m in matches)
                {
                    if (m is { })
Example #2
0
        /// <summary>
        /// Returns all boundaries matching the pattern
        /// </summary>
        /// <param name="pattern">Search pattern</param>
        /// <param name="boundary">Content boundary</param>
        /// <param name="searchIn">Search in command</param>
        /// <returns></returns>
        public bool MatchPattern(SearchPattern pattern, Boundary boundary, SearchCondition condition)
        {
            bool result = false;

            Boundary scope = ParseSearchBoundary(boundary, condition.SearchIn ?? "finding-only");

            string          text    = _content.Substring(scope.Index, scope.Length);
            List <Boundary> matches = MatchPattern(pattern, text);

            foreach (Boundary match in matches)
            {
                Boundary translatedBoundary = new Boundary()
                {
                    Length = match.Length,
                    Index  = match.Index + scope.Index
                };
                if (ScopeMatch(pattern, translatedBoundary))
                {
                    result = true;
                }
            }

            return(result);
        }
Example #3
0
 /// <summary>
 /// Returns all boundaries matching the pattern
 /// </summary>
 /// <param name="pattern">Search pattern</param>
 /// <returns>List of boundaries</returns>
 public List <Boundary> MatchPattern(SearchPattern pattern)
 {
     return(MatchPattern(pattern, _content));
 }