Ejemplo n.º 1
0
        /// <inheritdoc/>
        public override ISegmentMatch Match(IEnumerable <string> input)
        {
            var matches     = new List <string>();
            var matchAndAdd = new Func <string, bool>((string s) =>
            {
                if (s == String)
                {
                    matches.Add(s);
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            if (Occurrences == SegmentOccurrence.Single)
            {
                matchAndAdd(input.First());
            }
            else
            {
                var inputAsArray = input.ToArray();
                if (matchAndAdd(inputAsArray[0]) && inputAsArray.Length > 1)
                {
                    for (var inputIndex = 1; inputIndex < inputAsArray.Length; inputIndex++)
                    {
                        if (!matchAndAdd(inputAsArray[inputIndex]))
                        {
                            break;
                        }
                    }
                }
            }

            IEnumerable <ISegmentMatch> matchesFromChildren = new ISegmentMatch[0];

            if (Optional == true || matches.Count > 0)
            {
                matchesFromChildren = MatchChildren(input, matches);
            }

            var segmentMatch = new SegmentMatch(String, this, matches, matchesFromChildren);

            return(segmentMatch);
        }
        /// <inheritdoc/>
        public override ISegmentMatch Match(IEnumerable <string> input)
        {
            var matches = new List <string>();

            IEnumerable <ISegmentMatch> matchesFromChildren = new ISegmentMatch[0];

            if (Occurrences == SegmentOccurrence.Single)
            {
                matches.Add(input.First());
                matchesFromChildren = MatchChildren(input, matches);
            }
            else
            {
                matches.AddRange(input);
            }

            var match = new SegmentMatch(VariableName, this, matches, matchesFromChildren);

            return(match);
        }