MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / match_like_pattern

Method match_like_pattern

graphlite/src/exec/executor.rs:5461–5504  ·  view source on GitHub ↗

Match a string against a LIKE pattern with SQL-style wildcards

(&self, text: &str, pattern: &str)

Source from the content-addressed store, hash-verified

5459
5460 /// Match a string against a LIKE pattern with SQL-style wildcards
5461 fn match_like_pattern(&self, text: &str, pattern: &str) -> Result<Value, ExecutionError> {
5462 // Convert SQL LIKE pattern to regex
5463 // % matches any sequence of characters (including empty)
5464 // _ matches exactly one character
5465 let mut regex_pattern = String::new();
5466 regex_pattern.push('^'); // Anchor to start
5467
5468 let mut chars = pattern.chars().peekable();
5469 while let Some(ch) = chars.next() {
5470 match ch {
5471 '%' => regex_pattern.push_str(".*"),
5472 '_' => regex_pattern.push('.'),
5473 '\\' => {
5474 // Handle escape sequences
5475 if let Some(next_ch) = chars.next() {
5476 match next_ch {
5477 '%' => regex_pattern.push('%'),
5478 '_' => regex_pattern.push('_'),
5479 '\\' => regex_pattern.push_str("\\\\"),
5480 _ => {
5481 regex_pattern.push('\\');
5482 regex_pattern.push(next_ch);
5483 }
5484 }
5485 } else {
5486 regex_pattern.push('\\');
5487 }
5488 }
5489 // Escape regex special characters
5490 '.' | '+' | '*' | '?' | '^' | '$' | '(' | ')' | '[' | ']' | '{' | '}' | '|' => {
5491 regex_pattern.push('\\');
5492 regex_pattern.push(ch);
5493 }
5494 _ => regex_pattern.push(ch),
5495 }
5496 }
5497
5498 regex_pattern.push('$'); // Anchor to end
5499
5500 // For now, implement a simple pattern matching without regex dependency
5501 // This is a basic implementation that handles % and _ wildcards
5502 let matches = self.simple_like_match(text, pattern);
5503 Ok(Value::Boolean(matches))
5504 }
5505
5506 /// Simple LIKE pattern matching without regex dependency
5507 fn simple_like_match(&self, text: &str, pattern: &str) -> bool {

Callers 1

evaluate_binary_opMethod · 0.80

Calls 2

nextMethod · 0.80
simple_like_matchMethod · 0.80

Tested by

no test coverage detected