MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / build_regex

Function build_regex

src/expr/src/scalar/like_pattern.rs:364–380  ·  view source on GitHub ↗

Builds a regular expression that matches some parsed Subpatterns.

(subpatterns: &[Subpattern], case_insensitive: bool)

Source from the content-addressed store, hash-verified

362
363/// Builds a regular expression that matches some parsed Subpatterns.
364fn build_regex(subpatterns: &[Subpattern], case_insensitive: bool) -> Result<Regex, EvalError> {
365 let mut r = String::from("^");
366 for sp in subpatterns {
367 sp.write_regex_to(&mut r);
368 }
369 r.push('$');
370 match Regex::new(&r, case_insensitive) {
371 Ok(regex) => Ok(regex),
372 Err(RegexCompilationError::PatternTooLarge { .. }) => Err(EvalError::LikePatternTooLong),
373 Err(RegexCompilationError::RegexError(regex::Error::CompiledTooBig(_))) => {
374 Err(EvalError::LikePatternTooLong)
375 }
376 Err(e) => Err(EvalError::Internal(
377 format!("build_regex produced invalid regex: {}", e).into(),
378 )),
379 }
380}
381
382// Unit Tests
383//

Callers 1

compileFunction · 0.70

Calls 2

write_regex_toMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected