Guest User

Additional code to FlimFlan.ReadableRex

a guest
Jun 18th, 2010
127
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×