| 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> |
| 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; |
| 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) { |
| 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) { |
| 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 |
|
|
| 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 |
|
|