| 92 | } |
| 93 | |
| 94 | bool RE2::Set::Compile() { |
| 95 | if (compiled_) { |
| 96 | LOG(DFATAL) << "RE2::Set::Compile() called more than once"; |
| 97 | return false; |
| 98 | } |
| 99 | compiled_ = true; |
| 100 | size_ = static_cast<int>(elem_.size()); |
| 101 | |
| 102 | // Sort the elements by their patterns. This is good enough for now |
| 103 | // until we have a Regexp comparison function. (Maybe someday...) |
| 104 | std::sort(elem_.begin(), elem_.end(), |
| 105 | [](const Elem& a, const Elem& b) -> bool { |
| 106 | return a.first < b.first; |
| 107 | }); |
| 108 | |
| 109 | PODArray<re2::Regexp*> sub(size_); |
| 110 | for (int i = 0; i < size_; i++) |
| 111 | sub[i] = elem_[i].second; |
| 112 | elem_.clear(); |
| 113 | elem_.shrink_to_fit(); |
| 114 | |
| 115 | Regexp::ParseFlags pf = static_cast<Regexp::ParseFlags>( |
| 116 | options_.ParseFlags()); |
| 117 | re2::Regexp* re = re2::Regexp::Alternate(sub.data(), size_, pf); |
| 118 | |
| 119 | prog_.reset(Prog::CompileSet(re, anchor_, options_.max_mem())); |
| 120 | re->Decref(); |
| 121 | return prog_ != nullptr; |
| 122 | } |
| 123 | |
| 124 | bool RE2::Set::Match(const StringPiece& text, std::vector<int>* v) const { |
| 125 | return Match(text, v, NULL); |