예제 #1
0
        private IEnumerable <PcreMatch> MatchesIterator(string subject, PcreMatchSettings settings)
        {
            using (var context = settings.CreateMatchContext(subject))
            {
                var result = ExecuteMatch(context);

                if (result.ResultCode != MatchResultCode.Success)
                {
                    yield break;
                }

                var match = new PcreMatch(result);
                yield return(match);

                var options = context.AdditionalOptions;

                while (true)
                {
                    context.StartIndex        = match.GetStartOfNextMatchIndex();
                    context.AdditionalOptions = options | (match.Length == 0 ? PatternOptions.NotEmptyAtStart : PatternOptions.None);

                    result = ExecuteMatch(context);

                    if (result.ResultCode != MatchResultCode.Success)
                    {
                        yield break;
                    }

                    match = new PcreMatch(result);
                    yield return(match);
                }
            }
        }
예제 #2
0
        public PcreMatch Match(string subject, PcreMatchSettings settings)
        {
            if (subject == null)
            {
                throw new ArgumentNullException("subject");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (settings.StartIndex < 0 || settings.StartIndex > subject.Length)
            {
                throw new IndexOutOfRangeException("Invalid StartIndex value");
            }

            using (var context = settings.CreateMatchContext(subject))
            {
                return(new PcreMatch(ExecuteMatch(context)));
            }
        }