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

Xabier Oneca -- xOneca xoneca at gmail.com
Fri Aug 21 20:46:36 UTC 2015


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_,,_


More information about the busybox mailing list