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

Function build_subpatterns

src/expr/src/scalar/like_pattern.rs:320–361  ·  view source on GitHub ↗

Breaks a LIKE pattern into a chain of sub-patterns.

(pattern: &str)

Source from the content-addressed store, hash-verified

318
319/// Breaks a LIKE pattern into a chain of sub-patterns.
320fn build_subpatterns(pattern: &str) -> Result<Vec<Subpattern>, EvalError> {
321 let mut subpatterns = Vec::with_capacity(MAX_SUBPATTERNS);
322 let mut current = Subpattern::default();
323 let mut in_wildcard = true;
324 let mut in_escape = false;
325 for c in pattern.chars() {
326 match c {
327 c if !in_escape && c == DEFAULT_ESCAPE => {
328 in_escape = true;
329 in_wildcard = false;
330 }
331 '_' if !in_escape => {
332 if !in_wildcard {
333 current.suffix.shrink_to_fit();
334 subpatterns.push(mem::take(&mut current));
335 in_wildcard = true;
336 }
337 current.consume += 1;
338 }
339 '%' if !in_escape => {
340 if !in_wildcard {
341 current.suffix.shrink_to_fit();
342 subpatterns.push(mem::take(&mut current));
343 in_wildcard = true;
344 }
345 current.many = true;
346 }
347 c => {
348 current.suffix.push(c);
349 in_escape = false;
350 in_wildcard = false;
351 }
352 }
353 }
354 if in_escape {
355 return Err(EvalError::UnterminatedLikeEscapeSequence);
356 }
357 current.suffix.shrink_to_fit();
358 subpatterns.push(current);
359 subpatterns.shrink_to_fit();
360 Ok(subpatterns)
361}
362
363/// Builds a regular expression that matches some parsed Subpatterns.
364fn build_regex(subpatterns: &[Subpattern], case_insensitive: bool) -> Result<Regex, EvalError> {

Callers 1

compileFunction · 0.85

Calls 3

takeFunction · 0.85
shrink_to_fitMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected