--- code/trunk/pcre_scanner.cc 2007/02/24 21:41:21 87 +++ code/trunk/pcre_scanner.cc 2007/07/31 14:39:09 199 @@ -29,9 +29,14 @@ // // Author: Sanjay Ghemawat +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include -#include "config.h" + +#include "pcrecpp_internal.h" #include "pcre_scanner.h" using std::vector; @@ -43,6 +48,7 @@ input_(data_), skip_(NULL), should_skip_(false), + skip_repeat_(false), save_comments_(false), comments_(NULL), comments_offset_(0) { @@ -53,6 +59,7 @@ input_(data_), skip_(NULL), should_skip_(false), + skip_repeat_(false), save_comments_(false), comments_(NULL), comments_offset_(0) { @@ -63,15 +70,31 @@ delete comments_; } +void Scanner::SetSkipExpression(const char* re) { + delete skip_; + if (re != NULL) { + skip_ = new RE(re); + should_skip_ = true; + skip_repeat_ = true; + ConsumeSkip(); + } else { + skip_ = NULL; + should_skip_ = false; + skip_repeat_ = false; + } +} + void Scanner::Skip(const char* re) { delete skip_; if (re != NULL) { skip_ = new RE(re); should_skip_ = true; + skip_repeat_ = false; ConsumeSkip(); } else { skip_ = NULL; should_skip_ = false; + skip_repeat_ = false; } } @@ -118,19 +141,22 @@ // helper function to consume *skip_ and honour save_comments_ void Scanner::ConsumeSkip() { + const char* start_data = input_.data(); + while (skip_->Consume(&input_)) { + if (!skip_repeat_) { + // Only one skip allowed. + break; + } + } if (save_comments_) { - if (NULL == comments_) { + if (comments_ == NULL) { comments_ = new vector; } - const char *start_data = input_.data(); - skip_->Consume(&input_); // already pointing one past end, so no need to +1 int length = input_.data() - start_data; if (length > 0) { comments_->push_back(StringPiece(start_data, length)); } - } else { - skip_->Consume(&input_); } }