/[pcre]/code/trunk/pcrecpp.cc
ViewVC logotype

Diff of /code/trunk/pcrecpp.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 93 by nigel, Sat Feb 24 21:41:42 2007 UTC revision 199 by ph10, Tue Jul 31 14:39:09 2007 UTC
# Line 29  Line 29 
29  //  //
30  // Author: Sanjay Ghemawat  // Author: Sanjay Ghemawat
31    
32    #ifdef HAVE_CONFIG_H
33    #include <config.h>
34    #endif
35    
36  #include <stdlib.h>  #include <stdlib.h>
37  #include <stdio.h>  #include <stdio.h>
38  #include <ctype.h>  #include <ctype.h>
# Line 37  Line 41 
41  #include <errno.h>  #include <errno.h>
42  #include <string>  #include <string>
43  #include <algorithm>  #include <algorithm>
44  #include "config.h"  
45  // We need this to compile the proper dll on windows/msys.  This is copied  #include "pcrecpp_internal.h"
46  // from pcre_internal.h.  It would probably be better just to include that.  #include <pcre.h>
 #define PCRE_DEFINITION  /* Win32 __declspec(export) trigger for .dll */  
 #include "pcre.h"  
 #include "pcre_stringpiece.h"  
47  #include "pcrecpp.h"  #include "pcrecpp.h"
48    #include "pcre_stringpiece.h"
49    
50    
51  namespace pcrecpp {  namespace pcrecpp {
# Line 53  static const int kMaxArgs = 16; Line 55  static const int kMaxArgs = 16;
55  static const int kVecSize = (1 + kMaxArgs) * 3;  // results + PCRE workspace  static const int kVecSize = (1 + kMaxArgs) * 3;  // results + PCRE workspace
56    
57  // Special object that stands-in for no argument  // Special object that stands-in for no argument
58  Arg no_arg((void*)NULL);  PCRECPP_EXP_DECL Arg no_arg((void*)NULL);
59    
60  // If a regular expression has no error, its error_ field points here  // If a regular expression has no error, its error_ field points here
61  static const string empty_string;  static const string empty_string;
# Line 74  void RE::Init(const string& pat, const R Line 76  void RE::Init(const string& pat, const R
76    
77    re_partial_ = Compile(UNANCHORED);    re_partial_ = Compile(UNANCHORED);
78    if (re_partial_ != NULL) {    if (re_partial_ != NULL) {
79      // Check for complicated patterns.  The following change is      re_full_ = Compile(ANCHOR_BOTH);
     // conservative in that it may treat some "simple" patterns  
     // as "complex" (e.g., if the vertical bar is in a character  
     // class or is escaped).  But it seems good enough.  
     if (strchr(pat.c_str(), '|') == NULL) {  
       // Simple pattern: we can use position-based checks to perform  
       // fully anchored matches  
       re_full_ = re_partial_;  
     } else {  
       // We need a special pattern for anchored matches  
       re_full_ = Compile(ANCHOR_BOTH);  
     }  
80    }    }
81  }  }
82    
83  void RE::Cleanup() {  void RE::Cleanup() {
84    if (re_full_ != NULL && re_full_ != re_partial_) (*pcre_free)(re_full_);    if (re_full_ != NULL)         (*pcre_free)(re_full_);
85    if (re_partial_ != NULL)                         (*pcre_free)(re_partial_);    if (re_partial_ != NULL)      (*pcre_free)(re_partial_);
86    if (error_ != &empty_string)                     delete error_;    if (error_ != &empty_string)  delete error_;
87  }  }
88    
89    
# Line 471  int RE::TryMatch(const StringPiece& text Line 462  int RE::TryMatch(const StringPiece& text
462      return 0;      return 0;
463    }    }
464    
465    pcre_extra extra = { 0 };    pcre_extra extra = { 0, 0, 0, 0, 0, 0 };
466    if (options_.match_limit() > 0) {    if (options_.match_limit() > 0) {
467      extra.flags |= PCRE_EXTRA_MATCH_LIMIT;      extra.flags |= PCRE_EXTRA_MATCH_LIMIT;
468      extra.match_limit = options_.match_limit();      extra.match_limit = options_.match_limit();
# Line 504  int RE::TryMatch(const StringPiece& text Line 495  int RE::TryMatch(const StringPiece& text
495      rc = vecsize / 2;      rc = vecsize / 2;
496    }    }
497    
   if ((anchor == ANCHOR_BOTH) && (re_full_ == re_partial_)) {  
     // We need an extra check to make sure that the match extended  
     // to the end of the input string  
     assert(vec[0] == 0);                 // PCRE_ANCHORED forces starting match  
     if (vec[1] != text.size()) return 0; // Did not get ending match  
   }  
   
498    return rc;    return rc;
499  }  }
500    

Legend:
Removed from v.93  
changed lines
  Added in v.199

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12