Skip to content

Commit

Permalink
Clarify that RequiredPrefix() "zeroes" its outputs.
Browse files Browse the repository at this point in the history
Change-Id: I24799d87302165d78eb61544efdcdd04c3d3b9e2
Reviewed-on: https://code-review.googlesource.com/13030
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
junyer committed May 17, 2017
1 parent e7efc48 commit 7b88dbe
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 0 additions & 2 deletions re2/re2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ void RE2::Init(const StringPiece& pattern, const Options& options) {
return;
}

prefix_.clear();
prefix_foldcase_ = false;
re2::Regexp* suffix;
if (entire_regexp_->RequiredPrefix(&prefix_, &prefix_foldcase_, &suffix))
suffix_regexp_ = suffix;
Expand Down
2 changes: 1 addition & 1 deletion re2/regexp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ std::map<int, string>* Regexp::CaptureNames() {
// with a fixed string prefix. If so, returns the prefix and
// the regexp that remains after the prefix. The prefix might
// be ASCII case-insensitive.
bool Regexp::RequiredPrefix(string *prefix, bool *foldcase, Regexp** suffix) {
bool Regexp::RequiredPrefix(string* prefix, bool* foldcase, Regexp** suffix) {
// No need for a walker: the regexp must be of the form
// 1. some number of ^ anchors
// 2. a literal char or string
Expand Down
4 changes: 3 additions & 1 deletion re2/regexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ class Regexp {
// begin with a non-empty fixed string (perhaps after ASCII
// case-folding). If so, returns the prefix and the sub-regexp that
// follows it.
bool RequiredPrefix(string* prefix, bool *foldcase, Regexp** suffix);
// Callers should expect *prefix, *foldcase and *suffix to be "zeroed"
// regardless of the return value.
bool RequiredPrefix(string* prefix, bool* foldcase, Regexp** suffix);

private:
// Constructor allocates vectors as appropriate for operator.
Expand Down
8 changes: 5 additions & 3 deletions re2/testing/required_prefix_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ TEST(RequiredPrefix, SimpleTests) {
flags = flags | Regexp::Latin1;
Regexp* re = Regexp::Parse(t.regexp, flags, NULL);
CHECK(re) << " " << t.regexp;

string p;
bool f = false;
Regexp* s = NULL;
bool f;
Regexp* s;
CHECK_EQ(t.return_value, re->RequiredPrefix(&p, &f, &s))
<< " " << t.regexp << " " << (j==0 ? "latin1" : "utf") << " " << re->Dump();
<< " " << t.regexp << " " << (j==0 ? "latin1" : "utf")
<< " " << re->Dump();
if (t.return_value) {
CHECK_EQ(p, string(t.prefix))
<< " " << t.regexp << " " << (j==0 ? "latin1" : "utf");
Expand Down

0 comments on commit 7b88dbe

Please sign in to comment.