43 |
input_(data_), |
input_(data_), |
44 |
skip_(NULL), |
skip_(NULL), |
45 |
should_skip_(false), |
should_skip_(false), |
46 |
|
skip_repeat_(false), |
47 |
save_comments_(false), |
save_comments_(false), |
48 |
comments_(NULL), |
comments_(NULL), |
49 |
comments_offset_(0) { |
comments_offset_(0) { |
54 |
input_(data_), |
input_(data_), |
55 |
skip_(NULL), |
skip_(NULL), |
56 |
should_skip_(false), |
should_skip_(false), |
57 |
|
skip_repeat_(false), |
58 |
save_comments_(false), |
save_comments_(false), |
59 |
comments_(NULL), |
comments_(NULL), |
60 |
comments_offset_(0) { |
comments_offset_(0) { |
65 |
delete comments_; |
delete comments_; |
66 |
} |
} |
67 |
|
|
68 |
|
void Scanner::SetSkipExpression(const char* re) { |
69 |
|
delete skip_; |
70 |
|
if (re != NULL) { |
71 |
|
skip_ = new RE(re); |
72 |
|
should_skip_ = true; |
73 |
|
skip_repeat_ = true; |
74 |
|
ConsumeSkip(); |
75 |
|
} else { |
76 |
|
skip_ = NULL; |
77 |
|
should_skip_ = false; |
78 |
|
skip_repeat_ = false; |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
void Scanner::Skip(const char* re) { |
void Scanner::Skip(const char* re) { |
83 |
delete skip_; |
delete skip_; |
84 |
if (re != NULL) { |
if (re != NULL) { |
85 |
skip_ = new RE(re); |
skip_ = new RE(re); |
86 |
should_skip_ = true; |
should_skip_ = true; |
87 |
|
skip_repeat_ = false; |
88 |
ConsumeSkip(); |
ConsumeSkip(); |
89 |
} else { |
} else { |
90 |
skip_ = NULL; |
skip_ = NULL; |
91 |
should_skip_ = false; |
should_skip_ = false; |
92 |
|
skip_repeat_ = false; |
93 |
} |
} |
94 |
} |
} |
95 |
|
|
136 |
|
|
137 |
// helper function to consume *skip_ and honour save_comments_ |
// helper function to consume *skip_ and honour save_comments_ |
138 |
void Scanner::ConsumeSkip() { |
void Scanner::ConsumeSkip() { |
139 |
|
const char* start_data = input_.data(); |
140 |
|
while (skip_->Consume(&input_)) { |
141 |
|
if (!skip_repeat_) { |
142 |
|
// Only one skip allowed. |
143 |
|
break; |
144 |
|
} |
145 |
|
} |
146 |
if (save_comments_) { |
if (save_comments_) { |
147 |
if (NULL == comments_) { |
if (comments_ == NULL) { |
148 |
comments_ = new vector<StringPiece>; |
comments_ = new vector<StringPiece>; |
149 |
} |
} |
|
const char *start_data = input_.data(); |
|
|
skip_->Consume(&input_); |
|
150 |
// already pointing one past end, so no need to +1 |
// already pointing one past end, so no need to +1 |
151 |
int length = input_.data() - start_data; |
int length = input_.data() - start_data; |
152 |
if (length > 0) { |
if (length > 0) { |
153 |
comments_->push_back(StringPiece(start_data, length)); |
comments_->push_back(StringPiece(start_data, length)); |
154 |
} |
} |
|
} else { |
|
|
skip_->Consume(&input_); |
|
155 |
} |
} |
156 |
} |
} |
157 |
|
|