MCPcopy Index your code
hub / github.com/RustPython/RustPython / make_regex

Function make_regex

crates/stdlib/src/re.rs:266–287  ·  view source on GitHub ↗
(vm: &VirtualMachine, pattern: &str, flags: PyRegexFlags)

Source from the content-addressed store, hash-verified

264 }
265
266 fn make_regex(vm: &VirtualMachine, pattern: &str, flags: PyRegexFlags) -> PyResult<PyPattern> {
267 let unicode = if flags.unicode && flags.ascii {
268 return Err(vm.new_value_error("ASCII and UNICODE flags are incompatible"));
269 } else {
270 !flags.ascii
271 };
272 let r = RegexBuilder::new(pattern)
273 .case_insensitive(flags.ignorecase)
274 .multi_line(flags.multiline)
275 .dot_matches_new_line(flags.dotall)
276 .ignore_whitespace(flags.verbose)
277 .unicode(unicode)
278 .build()
279 .map_err(|err| match err {
280 regex::Error::Syntax(s) => vm.new_value_error(format!("Error in regex: {}", s)),
281 err => vm.new_value_error(format!("Error in regex: {:?}", err)),
282 })?;
283 Ok(PyPattern {
284 regex: r,
285 pattern: pattern.to_owned(),
286 })
287 }
288
289 /// Take a found regular expression and convert it to proper match object.
290 fn create_match(haystack: PyStrRef, captures: Captures) -> PyMatch {

Callers 6

match_Function · 0.85
searchFunction · 0.85
subFunction · 0.85
findallFunction · 0.85
splitFunction · 0.85
compileFunction · 0.85

Calls 4

newFunction · 0.85
ErrClass · 0.50
buildMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected