Beispiel #1
0
 // Determine if a string matches this regular expression and return
 // all of the matches in an array.  Returns null if no match.
 public RegexMatch[] Match(String str, RegexMatchOptions options,
                           int maxMatches)
 {
     if (str == null)
     {
         throw new ArgumentNullException("str");
     }
     else if (maxMatches < 0)
     {
         throw new ArgumentOutOfRangeException
                   ("maxMatches", "Must be non-negative");
     }
     if ((syntax & RegexSyntax.IgnoreCase) != 0)
     {
         str = str.ToLower();
     }
     lock (this)
     {
         if (handle != IntPtr.Zero)
         {
             options &= RegexMatchOptions.All;
             return((RegexMatch[])RegexpMethods.MatchInternal
                        (handle, str, maxMatches, (int)options,
                        typeof(RegexMatch)));
         }
         else
         {
             throw new ObjectDisposedException
                       (_("Exception_Disposed"));
         }
     }
 }
Beispiel #2
0
 public Regex(String pattern, RegexSyntax syntax)
 {
     if (pattern == null)
     {
         throw new ArgumentNullException("pattern");
     }
     this.syntax = syntax;
     if ((syntax & RegexSyntax.IgnoreCase) != 0)
     {
         pattern = pattern.ToLower();
     }
     if ((syntax & RegexSyntax.Wildcard) != 0)
     {
         pattern = FileSystemToPosix(pattern);
         syntax  = RegexSyntax.PosixExtended;
     }
     syntax &= (RegexSyntax.All &
                ~(RegexSyntax.Debug | RegexSyntax.IgnoreCase));
     lock (typeof(Regex))
     {
         // We lock down "Regex" while we do this because the
         // syntax setting in the GNU regex routines is not
         // thread-safe without it.
         handle = RegexpMethods.CompileWithSyntaxInternal
                      (pattern, (int)syntax);
     }
     if (handle == IntPtr.Zero)
     {
         throw new ArgumentException(_("Arg_InvalidRegex"));
     }
 }
Beispiel #3
0
 public bool Match(String str, RegexMatchOptions options)
 {
     if (str == null)
     {
         throw new ArgumentNullException("str");
     }
     if ((syntax & RegexSyntax.IgnoreCase) != 0)
     {
         str = str.ToLower();
     }
     lock (this)
     {
         if (handle != IntPtr.Zero)
         {
             options &= RegexMatchOptions.All;
             return(RegexpMethods.ExecInternal
                        (handle, str, (int)options) == 0);
         }
         else
         {
             throw new ObjectDisposedException
                       (_("Exception_Disposed"));
         }
     }
 }
Beispiel #4
0
 // Implement the IDisposable interface.
 public void Dispose()
 {
     lock (this)
     {
         if (handle != IntPtr.Zero)
         {
             RegexpMethods.FreeInternal(handle);
             handle = IntPtr.Zero;
         }
     }
 }