Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- namespace FlimFlan.ReadableRex
- {
- public class Alternation
- {
- // ...code...
- public Pattern Either(params Pattern[] options)
- {
- if (options == null) throw new ArgumentNullException("options");
- var length = options.Length;
- var lengthMinus1 = length - 1;
- if ((length == 0) || (length == 1))
- throw new InvalidOperationException("options.Length must be greater than 1");
- StringBuilder sb = new StringBuilder("(");
- for (int i = 0; i < length; i++)
- {
- sb.Append(options[i]);
- if (i != lengthMinus1)
- sb.Append("|");
- }
- sb.Append(")");
- var s = sb.ToString();
- return _precedingPattern.RegEx(s);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement