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

Diff of /code/trunk/pcre_scanner.cc

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

revision 77 by nigel, Sat Feb 24 21:40:45 2007 UTC revision 200 by ph10, Wed Aug 1 09:10:40 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 <vector>  #include <vector>
 #include <algorithm>     // for count()  
37  #include <assert.h>  #include <assert.h>
38  #include "config.h"  
39    #include "pcrecpp_internal.h"
40  #include "pcre_scanner.h"  #include "pcre_scanner.h"
41    
42  using std::vector;  using std::vector;
# Line 44  Scanner::Scanner() Line 48  Scanner::Scanner()
48      input_(data_),      input_(data_),
49      skip_(NULL),      skip_(NULL),
50      should_skip_(false),      should_skip_(false),
51        skip_repeat_(false),
52      save_comments_(false),      save_comments_(false),
53      comments_(NULL),      comments_(NULL),
54      comments_offset_(0) {      comments_offset_(0) {
# Line 54  Scanner::Scanner(const string& in) Line 59  Scanner::Scanner(const string& in)
59      input_(data_),      input_(data_),
60      skip_(NULL),      skip_(NULL),
61      should_skip_(false),      should_skip_(false),
62        skip_repeat_(false),
63      save_comments_(false),      save_comments_(false),
64      comments_(NULL),      comments_(NULL),
65      comments_offset_(0) {      comments_offset_(0) {
# Line 64  Scanner::~Scanner() { Line 70  Scanner::~Scanner() {
70    delete comments_;    delete comments_;
71  }  }
72    
73    void Scanner::SetSkipExpression(const char* re) {
74      delete skip_;
75      if (re != NULL) {
76        skip_ = new RE(re);
77        should_skip_ = true;
78        skip_repeat_ = true;
79        ConsumeSkip();
80      } else {
81        skip_ = NULL;
82        should_skip_ = false;
83        skip_repeat_ = false;
84      }
85    }
86    
87  void Scanner::Skip(const char* re) {  void Scanner::Skip(const char* re) {
88    delete skip_;    delete skip_;
89    if (re != NULL) {    if (re != NULL) {
90      skip_ = new RE(re);      skip_ = new RE(re);
91      should_skip_ = true;      should_skip_ = true;
92        skip_repeat_ = false;
93      ConsumeSkip();      ConsumeSkip();
94    } else {    } else {
95      skip_ = NULL;      skip_ = NULL;
96      should_skip_ = false;      should_skip_ = false;
97        skip_repeat_ = false;
98    }    }
99  }  }
100    
# Line 90  void Scanner::EnableSkip() { Line 112  void Scanner::EnableSkip() {
112  int Scanner::LineNumber() const {  int Scanner::LineNumber() const {
113    // TODO: Make it more efficient by keeping track of the last point    // TODO: Make it more efficient by keeping track of the last point
114    // where we computed line numbers and counting newlines since then.    // where we computed line numbers and counting newlines since then.
115    return 1 + std::count(data_.data(), input_.data(), '\n');    // We could use std:count, but not all systems have it. :-(
116      int count = 1;
117      for (const char* p = data_.data(); p < input_.data(); ++p)
118        if (*p == '\n')
119          ++count;
120      return count;
121  }  }
122    
123  int Scanner::Offset() const {  int Scanner::Offset() const {
# Line 114  bool Scanner::Consume(const RE& re, Line 141  bool Scanner::Consume(const RE& re,
141    
142  // helper function to consume *skip_ and honour save_comments_  // helper function to consume *skip_ and honour save_comments_
143  void Scanner::ConsumeSkip() {  void Scanner::ConsumeSkip() {
144      const char* start_data = input_.data();
145      while (skip_->Consume(&input_)) {
146        if (!skip_repeat_) {
147          // Only one skip allowed.
148          break;
149        }
150      }
151    if (save_comments_) {    if (save_comments_) {
152      if (NULL == comments_) {      if (comments_ == NULL) {
153        comments_ = new vector<StringPiece>;        comments_ = new vector<StringPiece>;
154      }      }
     const char *start_data = input_.data();  
     skip_->Consume(&input_);  
155      // already pointing one past end, so no need to +1      // already pointing one past end, so no need to +1
156      int length = input_.data() - start_data;      int length = input_.data() - start_data;
157      if (length > 0) {      if (length > 0) {
158        comments_->push_back(StringPiece(start_data, length));        comments_->push_back(StringPiece(start_data, length));
159      }      }
   } else {  
     skip_->Consume(&input_);  
160    }    }
161  }  }
162    

Legend:
Removed from v.77  
changed lines
  Added in v.200

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12