Ejemplo n.º 1
0
        /// <summary>
        /// Add an existing <see cref="RegexNegativeLookaheadAssertionNode"/> to the generator.
        /// </summary>
        /// <param name="group"><see cref="RegexNegativeLookaheadAssertionNode"/> to be added.</param>
        /// <returns><see cref="RegexGenerator"/></returns>
        /// <exception cref="NegativeLookaheadAssertionNotSupportedException">Negative lookahead assertion is not supported by <see cref="RegexLanguage"/>.</exception>
        public RegexGenerator AddNegativeLookaheadAssertion(RegexNegativeLookaheadAssertionNode negativeLookaheadAssertion)
        {
            if (!IsNegativeLookaheadAssertionSupported)
            {
                throw new NegativeLookaheadAssertionNotSupportedException(RegexLanguage);
            }

            return(Add(negativeLookaheadAssertion));
        }
        public virtual string ToNegativeLookaheadAssertionString(RegexNegativeLookaheadAssertionNode negativeLookaheadAssertion)
        {
            if (!IsNegativeLookaheadAssertionSupported)
            {
                throw new NegativeLookaheadAssertionNotSupportedException(RegexLanguage);
            }
            if (negativeLookaheadAssertion == null)
            {
                throw new ArgumentNullException(nameof(negativeLookaheadAssertion));
            }

            var sb = new StringBuilder();

            sb.Append(ToTokenString(RegexToken.NegativeLookaheadAssertionOpen))
            .Append(negativeLookaheadAssertion.IsInnerNodeIncluded ? ToString(negativeLookaheadAssertion.InnerNode) : negativeLookaheadAssertion.Pattern)
            .Append(ToTokenString(RegexToken.NegativeLookaheadAssertionClose));

            return(AddQuantifier(sb.ToString(), negativeLookaheadAssertion.Minimum, negativeLookaheadAssertion.Maximum, negativeLookaheadAssertion.RegexQuantifierOption));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create and add <see cref="RegexNegativeLookaheadAssertionNode"/> to the generator, and include another <see cref="RegexNode"/> inside.
        /// </summary>
        /// <param name="innerNode">An existing <see cref="RegexNode"/> to be included.</param>
        /// <param name="min">Optional minimum number of occurance.</param>
        /// <param name="max">Optional maximum number of occurance.</param>
        /// <param name="quantifierOption">Optional quantifier option.</param>
        /// <returns><see cref="RegexGenerator"/></returns>
        /// <exception cref="NegativeLookaheadAssertionNotSupportedException">Negative lookahead assertion is not supported by <see cref="RegexLanguage"/>.</exception>
        public RegexGenerator AddNegativeLookaheadAssertion(RegexNode innerNode, int?min = null, int?max = null, RegexQuantifierOption quantifierOption = RegexQuantifierOption.Greedy)
        {
            var negativeLookaheadAssertion = new RegexNegativeLookaheadAssertionNode(innerNode, min, max, quantifierOption);

            return(AddNegativeLookaheadAssertion(negativeLookaheadAssertion));
        }