Example #1
0
        /// <summary>
        /// Returns the index of the pattern in a string
        /// </summary>
        /// <param name="self"></param>
        /// <param name="text">The string in which to find the pattern</param>
        /// <param name="startPosition">Start index in the string</param>
        /// <param name="matchCase">true if a case sensitive match should be performed</param>
        /// <param name="separators"></param>
        /// <returns>A PatternScanResult containing information on where the pattern was found and also the text of the pattern</returns>
        public static PatternScanResult IndexIn(this Pattern self, string text, int startPosition, bool matchCase, string separators)
        {
            if (separators == null)
            {
            }
            else
            {
                self.Separators = separators;
            }

            if (!self.IsComplex)
            {
                if (!self.IsKeyword)
                {
                    return(self.SimpleFind(text, startPosition, matchCase));
                }

                return(self.SimpleFindKeyword(text, startPosition, matchCase));
            }
            if (!self.IsKeyword)
            {
                return(self.ComplexFind(text, startPosition));
            }

            return(self.ComplexFindKeyword(text, startPosition));
        }
Example #2
0
        private static PatternScanResult SimpleFindKeyword(this Pattern self, string text, int startPosition,
                                                           bool matchCase)
        {
            PatternScanResult res;

            while (true)
            {
                res = self.SimpleFind(text, startPosition, matchCase);
                if (res.Token == "")
                {
                    return(res);
                }

                if (self.CharIsSeparator(text, res.Index - 1) && self.CharIsSeparator(text, res.Index + res.Token.Length))
                {
                    return(res);
                }

                startPosition = res.Index + 1;
                if (startPosition >= text.Length)
                {
                    res.Token = "";
                    res.Index = 0;
                    return(res);
                }
            }
        }