Beispiel #1
0
        /// <summary>
        /// Matches the specified string.
        /// </summary>
        /// <param name="target">The string to match.</param>
        /// <param name="position">The position at the <paramref name="target"/> to start with.</param>
        /// <param name="matchingResults">The mathing results.</param>
        /// <returns>
        ///   <c>true</c> if matching was sucessfull; otherwise - <c>false</c>.
        /// </returns>
        public override MatchingResult Match(string target, int position, IList <string> matchingResults)
        {
            Assert.ArgumentNotNull(target, "target");
            Assert.ArgumentNotNull(matchingResults, "matchingResults");

            if (NextToken != null)
            {
                var res = NextToken.Match(target, position, matchingResults);
                return(res.IsSuccess
                           ? new MatchingResult {
                    IsSuccess = true, StartPosition = position, EndPosition = res.EndPosition
                }
                           : new MatchingResult {
                    IsSuccess = false
                });
            }

            if (position < target.Length)
            {
                var value = target.Substring(position);
                return(TryToSetValue(value, matchingResults)
                           ? new MatchingResult {
                    IsSuccess = true, StartPosition = position, EndPosition = target.Length - 1
                }
                           : new MatchingResult {
                    IsSuccess = false
                });
            }

            return(new MatchingResult {
                IsSuccess = true, StartPosition = position, EndPosition = target.Length - 1
            });
        }
Beispiel #2
0
        /// <summary>
        /// Matches the specified string.
        /// </summary>
        /// <param name="target">The string to match.</param>
        /// <param name="position">The position at the <paramref name="target"/> to start with.</param>
        /// <param name="matchingResults">The mathing results.</param>
        /// <returns>
        ///   <c>true</c> if matching was sucessfull; otherwise - <c>false</c>.
        /// </returns>
        public override MatchingResult Match(string target, int position, IList <string> matchingResults)
        {
            Assert.ArgumentNotNull(target, "target");
            Assert.ArgumentNotNull(matchingResults, "matchingResults");

            var foundPosition = target.IndexOf(SearchValue, position, StringComparison.Ordinal);

            if (foundPosition < 0)
            {
                return(new MatchingResult {
                    IsSuccess = false
                });
            }

            if (_anchored && foundPosition != position)
            {
                return(new MatchingResult {
                    IsSuccess = false
                });
            }

            var previousWildcardToken = _previousToken as WildcardToken;

            if (previousWildcardToken != null && !previousWildcardToken.TryToSetValue(target.Substring(position, foundPosition - position), matchingResults))
            {
                return(new MatchingResult {
                    IsSuccess = false
                });
            }

            if (NextToken != null)
            {
                var res = NextToken.Match(target, foundPosition + SearchValue.Length, matchingResults);
                return(res.IsSuccess
                           ? new MatchingResult {
                    IsSuccess = true, StartPosition = foundPosition, EndPosition = res.EndPosition
                }
                           : new MatchingResult {
                    IsSuccess = false
                });
            }

            return(new MatchingResult {
                IsSuccess = true, StartPosition = foundPosition, EndPosition = foundPosition + SearchValue.Length
            });
        }