[m-rev.] for review: add string.contains_match/2

Julien Fischer jfischer at opturion.com
Mon Jul 25 16:14:55 AEST 2022


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().

Julien.


More information about the reviews mailing list