Exemplo n.º 1
0
        public static RegexNode Add(RegexNode node1, RegexNode node2)
        {
            if (node1 == null || node2 == null)
            {
                throw new ArgumentException("Both nodes must be not null.");
            }

            RegexNodeConcatenation node1AsConcatenation = node1 as RegexNodeConcatenation;
            RegexNodeConcatenation node2AsConcatenation = node2 as RegexNodeConcatenation;

            if (node1AsConcatenation != null && node2AsConcatenation != null)
            {
                List<RegexNode> newChildNodes = new List<RegexNode>();
                newChildNodes.AddRange(node1AsConcatenation.ChildNodes);
                newChildNodes.AddRange(node2AsConcatenation.ChildNodes);

                RegexNodeConcatenation result = new RegexNodeConcatenation(newChildNodes);
                return result;
            }

            if (node1AsConcatenation != null)
            {
                List<RegexNode> newChildNodes = new List<RegexNode>(node1AsConcatenation.ChildNodes);
                newChildNodes.Add(node2);

                RegexNodeConcatenation result = new RegexNodeConcatenation(newChildNodes);
                return result;
            }

            if (node2AsConcatenation != null)
            {
                List<RegexNode> newChildNodes = new List<RegexNode>();
                newChildNodes.Add(node1);
                newChildNodes.AddRange(node2AsConcatenation.ChildNodes);

                RegexNodeConcatenation result = new RegexNodeConcatenation(newChildNodes);
                return result;
            }

            return new RegexNodeConcatenation(node1, node2);
        }
Exemplo n.º 2
0
        public static RegexNode Add(RegexNode node1, RegexNode node2)
        {
            if (node1 == null || node2 == null)
            {
                throw new ArgumentException("Both nodes must be not null.");
            }

            RegexNodeConcatenation node1AsConcatenation = node1 as RegexNodeConcatenation;
            RegexNodeConcatenation node2AsConcatenation = node2 as RegexNodeConcatenation;

            if (node1AsConcatenation != null && node2AsConcatenation != null)
            {
                List <RegexNode> newChildNodes = new List <RegexNode>();
                newChildNodes.AddRange(node1AsConcatenation.ChildNodes);
                newChildNodes.AddRange(node2AsConcatenation.ChildNodes);

                RegexNodeConcatenation result = new RegexNodeConcatenation(newChildNodes);
                return(result);
            }

            if (node1AsConcatenation != null)
            {
                List <RegexNode> newChildNodes = new List <RegexNode>(node1AsConcatenation.ChildNodes);
                newChildNodes.Add(node2);

                RegexNodeConcatenation result = new RegexNodeConcatenation(newChildNodes);
                return(result);
            }

            if (node2AsConcatenation != null)
            {
                List <RegexNode> newChildNodes = new List <RegexNode>();
                newChildNodes.Add(node1);
                newChildNodes.AddRange(node2AsConcatenation.ChildNodes);

                RegexNodeConcatenation result = new RegexNodeConcatenation(newChildNodes);
                return(result);
            }

            return(new RegexNodeConcatenation(node1, node2));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Generates a Regex object from a list of RegexNode and applies a combination of RegexOptions to it.
 /// </summary>
 /// <param name="regexOptions">Combination of RegexOption flags to be applied to the Regex.</param>
 /// <param name="regexNodes">Top-level nodes for the Regex.</param>
 /// <returns>A new instance of Regex which corresponds to the specified RegexNode list.</returns>
 public static Regex Build(RegexOptions regexOptions, params RegexNode[] regexNodes)
 {
     RegexNodeConcatenation concatenation = new RegexNodeConcatenation(regexNodes);
     return Build(regexOptions, concatenation);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Generates a Regex object from a list of RegexNode and applies a combination of RegexOptions to it.
        /// </summary>
        /// <param name="regexOptions">Combination of RegexOption flags to be applied to the Regex.</param>
        /// <param name="regexNodes">Top-level nodes for the Regex.</param>
        /// <returns>A new instance of Regex which corresponds to the specified RegexNode list.</returns>
        public static Regex Build(RegexOptions regexOptions, params RegexNode[] regexNodes)
        {
            RegexNodeConcatenation concatenation = new RegexNodeConcatenation(regexNodes);

            return(Build(regexOptions, concatenation));
        }