Example #1
0
            private IExpression ParseOctalEscapeOrNumberedBackreference()
            {
                int    endIndex     = GetNumberEndIndex();
                string numberString = regex.Substring(index, endIndex - index);

                index = endIndex; // swallow number
                int number = Int32.Parse(numberString);

                if (number >= 1 && number <= 9)
                {
                    return(Backreference.For(number));
                }
                else if (numberString[0] == '8' || numberString[0] == '9')
                {
                    return(CharacterEscapes.Octal(numberString));
                }
                else if (number >= 10)
                {
                    if (number < groupNames.Count)
                    {
                        return(Backreference.For(number));
                    }
                    else
                    {
                        return(CharacterEscapes.Octal(numberString));
                    }
                }
                // The Regex constructor to prevent backreferences to \0 and invalid octal codes
                throw new InvalidOperationException();
            }
Example #2
0
            private IExpression ParseNamedBackreference()
            {
                ++index; // swallow 'k'
                bool useQuotes   = regex[index] == '\'';
                char closingChar = useQuotes ? '\'' : '>';

                ++index; // swallow opening char
                int    endIndex = regex.IndexOf(closingChar, index);
                string name     = regex.Substring(index, endIndex - index);

                index = endIndex + 1;  // swallow closing char
                return(Backreference.For(name, useQuotes));
            }