added more functions from original code, added macro

This commit is contained in:
Vlasislav Kashin
2025-07-02 18:02:47 +03:00
parent 929fdbae8a
commit d0fb47705a
14 changed files with 1177 additions and 41 deletions

View File

@@ -1,6 +1,7 @@
use log::{error};
use super::regex_util::{RegexFullMatch, RegexConsume};
use crate::{interfaces, proto_gen::phonemetadata::PhoneNumberDesc, regexp_cache::{self, RegexCache}};
use crate::{interfaces, proto_gen::phonemetadata::PhoneNumberDesc, regexp_cache::{ErrorInvalidRegex, RegexCache}};
pub struct RegexBasedMatcher {
cache: RegexCache,
@@ -15,23 +16,15 @@ impl RegexBasedMatcher {
&self, phone_number: &str,
number_pattern: &str,
allow_prefix_match: bool
) -> Result<bool, regexp_cache::ErrorInvalidRegex> {
) -> Result<bool, ErrorInvalidRegex> {
let regexp = self.cache.get_regex(number_pattern)?;
// find first occurrence
if let Some(mat) = regexp.find(phone_number) {
// if first position is not matched none of scenarios are possible
if mat.start() != 0 {
return Ok(false);
}
// full match
if mat.end() == phone_number.len() {
return Ok(true);
} else if allow_prefix_match {
return Ok(true);
}
if allow_prefix_match {
Ok(regexp.consume_start(phone_number).is_some())
} else {
Ok(regexp.full_match(phone_number))
}
Ok(false)
}
}