MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / like_op

Method like_op

crates/gitql-core/src/values/text.rs:266–288  ·  view source on GitHub ↗
(&self, other: &Box<dyn Value>)

Source from the content-addressed store, hash-verified

264 }
265
266 fn like_op(&self, other: &Box<dyn Value>) -> Result<Box<dyn Value>, String> {
267 let pattern_text = other.as_text().unwrap();
268 let pattern = &format!(
269 "^{}$",
270 pattern_text
271 .to_lowercase()
272 .replace('%', ".*")
273 .replace('_', ".")
274 );
275
276 let regex_builder = RegexBuilder::new(pattern)
277 .multi_line(true)
278 .unicode(true)
279 .build();
280
281 match regex_builder {
282 Ok(regex) => {
283 let is_match = regex.is_match(&self.value.to_lowercase());
284 Ok(Box::new(BoolValue { value: is_match }))
285 }
286 Err(error_message) => Err(error_message.to_string()),
287 }
288 }
289
290 fn glob_op(&self, other: &Box<dyn Value>) -> Result<Box<dyn Value>, String> {
291 let pattern_text = other.as_text().unwrap();

Callers 1

evaluate_likeFunction · 0.45

Calls 1

as_textMethod · 0.80

Tested by

no test coverage detected