Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(577)

Unified Diff: regexp2000/src/parser.cc

Issue 11203: * Changed string-representation of regexps to handle unprintable chars. (Closed)
Patch Set: Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: regexp2000/src/parser.cc
diff --git a/regexp2000/src/parser.cc b/regexp2000/src/parser.cc
index 33d34aa686348aba0d343f339900182ff7e3f0e0..c3d21161158e2237d3336776033b40f7ea8a4c79 100644
--- a/regexp2000/src/parser.cc
+++ b/regexp2000/src/parser.cc
@@ -387,6 +387,10 @@ void RegExpBuilder::AddEmpty() {
void RegExpBuilder::AddAtom(RegExpTree* term) {
+ if (term->IsEmpty()) {
+ AddEmpty();
+ return;
+ }
if (term->IsTextElement()) {
FlushCharacters();
text_.Add(term);
@@ -470,6 +474,16 @@ void RegExpBuilder::AddQuantifierToAtom(int min, int max, bool is_greedy) {
} else if (terms_.length() > 0) {
ASSERT(last_added_ == ADD_ATOM);
atom = terms_.RemoveLast();
+ if (atom->IsLookahead() || atom->IsAssertion()) {
Christian Plesner Hansen 2008/11/17 10:54:35 I wonder if this is worthwhile?
Lasse Reichstein 2008/11/17 11:26:32 It probably isn't. It's optimizing the case where
+ // Guaranteed not to match a non-empty string.
+ // Assertion as an atom can happen as, e.g., (?:\b)
+ LAST(ADD_TERM);
+ if (min == 0) {
+ return;
+ }
+ terms_.Add(atom);
+ return;
+ }
} else {
// Only call immediately after adding an atom or character!
UNREACHABLE();

Powered by Google App Engine
This is Rietveld 408576698