regex: define the predicate matches_string (#11422)
parent
f2f7abe2f4
commit
2533f06e1b
|
@ -556,6 +556,13 @@ fn test_regex(){
|
||||||
continue
|
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
|
// rerun to test consistency
|
||||||
tmp_str1 := to.src.clone()
|
tmp_str1 := to.src.clone()
|
||||||
start1, end1 := re.match_string(tmp_str1)
|
start1, end1 := re.match_string(tmp_str1)
|
||||||
|
@ -637,4 +644,4 @@ fn test_quantifier_sequences(){
|
||||||
}
|
}
|
||||||
assert re_err == regex.err_syntax_error
|
assert re_err == regex.err_syntax_error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,6 +144,12 @@ pub fn (mut re RE) match_string(in_txt string) (int, int) {
|
||||||
return start, end
|
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
|
* Finders
|
||||||
|
|
Loading…
Reference in New Issue