예제 #1
0
        /// <inheritdoc/>
        public ISegmentMatches Match(string stringToMatch)
        {
            Logger.Internal.Trace($"Trying to match the following string '{stringToMatch}' - separators : '{string.Join(" ",Separators)}'");

            var matches = new List <ISegmentMatch>();
            var strings = stringToMatch.Split(Separators);

            var segments            = Segments.ToArray();
            var currentStringIndex  = 0;
            var currentSegmentIndex = 0;

            Logger.Internal.Trace($"Segments count: {segments.Length}");

            while (currentSegmentIndex < segments.Length)
            {
                var segment = segments[currentSegmentIndex];
                Logger.Internal.Trace($"Current segment : {segment}");

                var length = strings.Length - currentStringIndex;
                if (length <= 0)
                {
                    break;
                }

                if (!segment.Fixed && currentSegmentIndex < segments.Length - 1)
                {
                    length = FindNextStop(strings, segments, currentStringIndex, currentSegmentIndex, segment, length);
                }

                if (length <= 0)
                {
                    break;
                }

                var match = MatchStrings(strings, currentStringIndex, segment, length);
                if (!match.HasMatch && !segment.Optional)
                {
                    return(new SegmentMatches(new ISegmentMatch[0]));
                }
                if (match.HasMatch)
                {
                    Logger.Internal.Trace($"Match found");
                    matches.Add(match);
                    matches.AddRange(match.Children);
                    currentStringIndex += match.Values.Count();
                }
                currentSegmentIndex++;
            }

            var segmentMatches = new SegmentMatches(matches);

            return(segmentMatches);
        }
예제 #2
0
        /// <inheritdoc/>
        public ISegmentMatches Match(string stringToMatch)
        {
            var matches = new List <ISegmentMatch>();
            var strings = stringToMatch.Split(Separators);

            var segments            = Segments.ToArray();
            var currentStringIndex  = 0;
            var currentSegmentIndex = 0;

            while (currentSegmentIndex < segments.Length)
            {
                var segment = segments[currentSegmentIndex];
                var length  = strings.Length - currentStringIndex;
                if (length <= 0)
                {
                    break;
                }

                if (!segment.Fixed && currentSegmentIndex < segments.Length - 1)
                {
                    length = FindNextStop(strings, segments, currentStringIndex, currentSegmentIndex, segment, length);
                }

                if (length <= 0)
                {
                    break;
                }

                var match = MatchStrings(strings, currentStringIndex, segment, length);
                if (!match.HasMatch && !segment.Optional)
                {
                    return(new SegmentMatches(new ISegmentMatch[0]));
                }
                if (match.HasMatch)
                {
                    matches.Add(match);
                    matches.AddRange(match.Children);
                    currentStringIndex += match.Values.Count();
                }
                currentSegmentIndex++;
            }

            var segmentMatches = new SegmentMatches(matches);

            return(segmentMatches);
        }