Exemplo n.º 1
0
        private static IList <IOccurrence> StringOccurrences(string text, string pattern)
        {
            // Loop through all instances of the string 'text'.
            IList <IOccurrence> occurrences = new Occurrences();

            int i = 0;

            while ((i = text.IndexOf(pattern, i)) != -1)
            {
                occurrences.Add(new Occurrence(i, i + pattern.Length));
                i += pattern.Length;
            }
            return(occurrences);
        }
Exemplo n.º 2
0
        private static Occurrences ExceptionMatches(string input, IList <Expression> exceptions)
        {
            Occurrences exceptionMatches = new Occurrences();

            if (exceptions == null || (exceptions.Count == 0))
            {
                return(exceptionMatches);
            }
            foreach (Expression exception in exceptions)
            {
                foreach (Occurrence pointer in exception.Occurrences(input))
                {
                    exceptionMatches.Add(pointer);
                }
            }
            return(exceptionMatches);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Pointers to start indexes in the input, where patterns starts.
        /// </summary>
        /// <param name="input">Input text in which the pattern is searched.</param>
        /// <returns>List of integers. If there is no pattern match, empty list is returned.</returns>
        // při porovnánání výjimky se pak zjišťuje, jestli výskyt je mezi těmito krajními body
        public IList <IOccurrence> Occurrences(string input)
        {
            IList <IOccurrence> occurences = new Occurrences();

            switch (Format)
            {
            case ChangeFormat.String:
                occurences = StringOccurrences(input, Pattern);
                break;

            case ChangeFormat.RegularExpression:
                MatchCollection matches = _regex.Matches(input);
                foreach (Match match in matches)
                {
                    occurences.Add(new Occurrence(match.Index, match.Index + match.Length));
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(occurences);
        }