[RFC/PATCH v2 3/5] libbb: add ends_with() function

Tito farmatito at tiscali.it
Fri Aug 21 21:26:55 UTC 2015



On 08/21/2015 10:46 PM, Xabier Oneca -- xOneca wrote:
> Hello tito,
>
>> [...]
>>
>>   ./test
>> 'testprova' ends_with 'test' = no
>> 'testprova' ends_with 'prova' = yes
>> 'test' ends_with 'prova' = no
>> 'test' ends_with 'testprova' = no
>> '' ends_with 'testprova' = no
>> 'test' ends_with '' = yes
>>
>> and I wonder if the last test result is correct:
>>
>> 'test' ends_with '' = yes
>>
>> Just for fun I've also added a different implementation that
>> seems to do the right thing (at least for me):
>>
>> 'testprova' ends_with 'test' = no
>> 'testprova' ends_with 'prova' = yes
>> 'test' ends_with 'prova' = no
>> 'test' ends_with 'testprova' = no
>> '' ends_with 'testprova' = no
>> 'test' ends_with '' = no
>
> Well, The Right Thing(tm) depends on the use case of ends_with()...
>
> To me that last line is correct, because "test\0" *ends* wtih "\0".
> But in a context where key should not be empty your exception may make
> sense.
>
> Cheers,
>
> Xabier Oneca_,,_
>

Hi,

what sense would it make to check if str\0 ends_with \0 if all strings 
do end with \0 ?

Ciao,
Tito


More information about the busybox mailing list