Skip to content

Commit

Permalink
Don't use C++17 'if' initialization
Browse files Browse the repository at this point in the history
The if (bool foo = bar; bar != baz) style of if statement is only
available from C++17 onwards but users compiling against system
libraries may be using older C++ compilers.
  • Loading branch information
mudge committed Sep 20, 2023
1 parent 70923ea commit 07794e0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ext/re2/re2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,9 @@ static re2::StringPiece *re2_matchdata_find_match(VALUE idx, const VALUE self) {
} else {
const char *name = SYMBOL_P(idx) ? rb_id2name(SYM2ID(idx)) : StringValuePtr(idx);
const std::map<std::string, int>& groups = p->pattern->NamedCapturingGroups();
std::map<std::string, int>::const_iterator search = groups.find(name);

if (std::map<std::string, int>::const_iterator search = groups.find(name); search != groups.end()) {
if (search != groups.end()) {
id = search->second;
} else {
return NULL;
Expand Down Expand Up @@ -502,8 +503,9 @@ static VALUE re2_matchdata_named_match(const char* name, const VALUE self) {
Data_Get_Struct(m->regexp, re2_pattern, p);

const std::map<std::string, int>& groups = p->pattern->NamedCapturingGroups();
std::map<std::string, int>::const_iterator search = groups.find(name);

if (std::map<std::string, int>::const_iterator search = groups.find(name); search != groups.end()) {
if (search != groups.end()) {
return re2_matchdata_nth_match(search->second, self);
} else {
return Qnil;
Expand Down Expand Up @@ -719,8 +721,9 @@ static VALUE re2_matchdata_deconstruct_keys(const VALUE self, const VALUE keys)
VALUE key = rb_ary_entry(keys, i);
Check_Type(key, T_SYMBOL);
const char *name = rb_id2name(SYM2ID(key));
std::map<std::string, int>::const_iterator search = groups.find(name);

if (std::map<std::string, int>::const_iterator search = groups.find(name); search != groups.end()) {
if (search != groups.end()) {
rb_hash_aset(capturing_groups, key, re2_matchdata_nth_match(search->second, self));
} else {
break;
Expand Down

0 comments on commit 07794e0

Please sign in to comment.