regex: define the predicate matches_string (#11422)

pull/11426/head
Xavier Noria 2021-09-07 06:01:23 +02:00 committed by GitHub
parent f2f7abe2f4
commit 2533f06e1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -556,6 +556,13 @@ fn test_regex(){
continue
}
// test the match predicate
if to.s >= 0 {
assert re.matches_string(to.src)
} else {
assert !re.matches_string(to.src)
}
// rerun to test consistency
tmp_str1 := to.src.clone()
start1, end1 := re.match_string(tmp_str1)
@ -637,4 +644,4 @@ fn test_quantifier_sequences(){
}
assert re_err == regex.err_syntax_error
}
}
}

View File

@ -144,6 +144,12 @@ pub fn (mut re RE) match_string(in_txt string) (int, int) {
return start, end
}
// matches_string Checks if the pattern matches the in_txt string
pub fn (mut re RE) matches_string(in_txt string) bool {
start, _ := re.match_string(in_txt)
return start != no_match_found
}
/******************************************************************************
*
* Finders