MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / Init

Method Init

extern/re2/re2/re2.cc:174–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172}
173
174void RE2::Init(const StringPiece& pattern, const Options& options) {
175 static std::once_flag empty_once;
176 std::call_once(empty_once, []() {
177 empty_string.reset(new std::string);
178 empty_named_groups.reset(new std::map<std::string, int>);
179 empty_group_names.reset(new std::map<int, std::string>);
180 });
181
182 pattern_.assign(pattern.data(), pattern.size());
183 options_.Copy(options);
184 entire_regexp_ = NULL;
185 error_ = empty_string.get();
186 error_code_ = NoError;
187 error_arg_.clear();
188 prefix_.clear();
189 prefix_foldcase_ = false;
190 suffix_regexp_ = NULL;
191 prog_ = NULL;
192 num_captures_ = -1;
193 is_one_pass_ = false;
194
195 rprog_ = NULL;
196 named_groups_ = NULL;
197 group_names_ = NULL;
198
199 RegexpStatus status;
200 entire_regexp_ = Regexp::Parse(
201 pattern_,
202 static_cast<Regexp::ParseFlags>(options_.ParseFlags()),
203 &status);
204 if (entire_regexp_ == NULL) {
205 if (options_.log_errors()) {
206 LOG(ERROR) << "Error parsing '" << trunc(pattern_) << "': "
207 << status.Text();
208 }
209 error_ = new std::string(status.Text());
210 error_code_ = RegexpErrorToRE2(status.code());
211 error_arg_ = std::string(status.error_arg());
212 return;
213 }
214
215 re2::Regexp* suffix;
216 if (entire_regexp_->RequiredPrefix(&prefix_, &prefix_foldcase_, &suffix))
217 suffix_regexp_ = suffix;
218 else
219 suffix_regexp_ = entire_regexp_->Incref();
220
221 // Two thirds of the memory goes to the forward Prog,
222 // one third to the reverse prog, because the forward
223 // Prog has two DFAs but the reverse prog has one.
224 prog_ = suffix_regexp_->CompileToProg(options_.max_mem()*2/3);
225 if (prog_ == NULL) {
226 if (options_.log_errors())
227 LOG(ERROR) << "Error compiling '" << trunc(pattern_) << "'";
228 error_ = new std::string("pattern too large - compile failed");
229 error_code_ = RE2::ErrorPatternTooLarge;
230 return;
231 }

Callers

nothing calls this directly

Calls 15

ParseFunction · 0.85
RegexpErrorToRE2Function · 0.85
ParseFlagsMethod · 0.80
log_errorsMethod · 0.80
TextMethod · 0.80
codeMethod · 0.80
RequiredPrefixMethod · 0.80
CompileToProgMethod · 0.80
max_memMethod · 0.80
NumCapturesMethod · 0.80
IsOnePassMethod · 0.80
truncFunction · 0.70

Tested by

no test coverage detected