MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / compile

Method compile

lib/regex.cpp:192–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190 };
191
192 std::string PcreRegex::compile()
193 {
194 if (mRe)
195 return "regular expression has already been compiled";
196
197 const char *pcreCompileErrorStr = nullptr;
198 int erroffset = 0;
199 pcre * const re = pcre_compile(mPattern.c_str(),0,&pcreCompileErrorStr,&erroffset,nullptr);
200 if (!re) {
201 if (pcreCompileErrorStr)
202 return pcreCompileErrorStr;
203 return "unknown error";
204 }
205
206 // Optimize the regex, but only if PCRE_CONFIG_JIT is available
207#ifdef PCRE_CONFIG_JIT
208 const char *pcreStudyErrorStr = nullptr;
209 pcre_extra * const pcreExtra = pcre_study(re, PCRE_STUDY_JIT_COMPILE, &pcreStudyErrorStr);
210 // pcre_study() returns NULL for both errors and when it can not optimize the regex.
211 // The last argument is how one checks for errors.
212 // It is NULL if everything works, and points to an error string otherwise.
213 if (pcreStudyErrorStr) {
214 // pcre_compile() worked, but pcre_study() returned an error. Free the resources allocated by pcre_compile().
215 pcre_free(re);
216 return std::string(pcreStudyErrorStr) + " (pcre_study)";
217 }
218 mExtra = pcreExtra;
219#endif
220
221 mRe = re;
222
223 return "";
224 }
225
226 std::string PcreRegex::match(const std::string& str, const MatchFn& matchFn) const
227 {

Callers 15

scan_packageFunction · 0.80
__split_resultsFunction · 0.80
__init__Method · 0.80
createAndCompileRegexFunction · 0.80
validate_regexFunction · 0.80
getAddonRulesFunction · 0.80
misra_5_4Method · 0.80
misra_5_5Method · 0.80
misra_7_1Method · 0.80
misra_7_3Method · 0.80
misra_12_1_sizeofMethod · 0.80
misra_20_13Method · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected