//=-- Regex.h - Regular Expressions for C++ -------------------------*- C++ -*-=
//
// Regular expressions are a cool toy used for filter matching.  This class
// interfaces to the C implementation of a regexp package named "pcre".
// pcre is a so called "perl compatible regular expression" library, that is
// free for all uses.  This library is statically linked in, source is in the
// pcregex directory.
//
// After a regex is created, the error should be checked to see if it was 
// successful or not.
//
//=----------------------------------------------------------------------------=
//  This file is copyright (c) 1997-2000 Chris Lattner
//=----------------------------------------------------------------------------=

#ifndef REGEXP_H
#define REGEXP_H

typedef void pcre_extra;
typedef void pcre;

#include "PlatformAbstraction.h"

class MSAPI regex {
public :
  regex(const char *pattern);
  ~regex();

  // Compile a new pattern...
  int CompileNew(const char *pattern);

  // Returns true if an error occurred.
  inline int GetError() {
    return ErrorMessage != 0;
  }

  // Execute - Return > 0 if a match is found!
  int Execute(const char *Text);

  // FindMatch - Return > 0 if a match is found, and if one is found, set *From
  // to be the start of the match and *To to be the end of the match...
  //
  int FindMatch(const char *Strin, int *From, int *To);

  inline int Match(const char *Text) {
    return Execute(Text) > 0;
  }

  const char *GetErrorMessage();

private :
  regex(const regex &);  // Never implement copy ctor!

  pcre       *Compiled;
  pcre_extra *ExtraInfo;
  const char *LastString;

  const char *ErrorMessage;
};

#endif
