daily pastebin goal
62%
SHARE
TWEET

Additional code to FlimFlan.ReadableRex

a guest Jun 18th, 2010 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Text;
  3.  
  4. namespace FlimFlan.ReadableRex
  5. {
  6.     public class Alternation
  7.     {
  8.         // ...code...
  9.         public Pattern Either(params Pattern[] options)
  10.         {
  11.             if (options == null) throw new ArgumentNullException("options");
  12.             var length = options.Length;
  13.             var lengthMinus1 = length - 1;
  14.             if ((length == 0) || (length == 1))
  15.                 throw new InvalidOperationException("options.Length must be greater than 1");
  16.             StringBuilder sb = new StringBuilder("(");
  17.             for (int i = 0; i < length; i++)
  18.             {
  19.                 sb.Append(options[i]);
  20.                 if (i != lengthMinus1)
  21.                     sb.Append("|");
  22.             }
  23.             sb.Append(")");
  24.             var s = sb.ToString();
  25.             return _precedingPattern.RegEx(s);
  26.         }
  27.     }
  28. }
RAW Paste Data
Top