[m-rev.] for review: add string.contains_match/2
Peter Wang
novalazy at gmail.com
Mon Jul 25 16:49:32 AEST 2022
On Mon, 25 Jul 2022 16:14:55 +1000 Julien Fischer <jfischer at opturion.com> wrote:
>
> On Mon, 25 Jul 2022, Peter Wang wrote:
>
> > On Mon, 25 Jul 2022 15:38:10 +1000 Julien Fischer <jfischer at opturion.com> wrote:
>
> >> %---------------------%
> >>
> >> +contains_match(P, String) :-
> >> + contains_match_loop(P, String, 0).
> >> +
> >> +:- pred contains_match_loop(pred(char)::in(pred(in) is semidet), string::in,
> >> + int::in) is semidet.
> >> +
> >> +contains_match_loop(P, String, Cur) :-
> >> + unsafe_index_next_repl(String, Cur, Next, Char, not_replaced),
> >> + ( if P(Char) then
> >> + true
> >> + else
> >> + contains_match_loop(P, String, Next)
> >> + ).
> >
> > If unsafe_index_next_repl returns replaced_code_unit(_) then P should
> > not succeed, but I think the loop should continue to test the rest of
> > the string.
>
> I don't have any objections to doing that, however it would not be
> consistent with how all_match/2 and contains_char/2 treat
> replaced_code_unit().
Hmm, I don't know what I was thinking when I updated those predicates,
if I was thinking at all.
It seems clear that:
- all_match should fail if the string contains any ill-formed sequences
- contains_char should succeed as long as the string contains the char
being tested for, even if it contains an ill-formed sequence or
anything else
I will try to look over the rest of the string predicates tomorrow.
Peter
More information about the reviews
mailing list