Hi Bruno, On 2026-02-27T08:35:24+0100, Bruno Haible wrote: > Hi Alejandro, > > > I was wondering if I should propose adding an alias for strpbrk(3). > > <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3670.txt> > > > > Plan9 has a synonym called strchrs(), and that is indeed a better name > > for strpbrk(3), since it's just a plural version of strchr(3). > > ... > > The following calls are equivalent: > > > > strchrnul(s, 'x'); > > stpcspn(s, "x"); > > If the function strpbrk was not already standardized in ISO C, > I agree that the Plan9 naming could help construct a family of > consistently named functions.
Agree, having done so a long time ago would have made the change much
better.
>
> However, because
> - all three functions are already standardized,
> - these functions with a set of characters in the second argument are
> not frequently used
> [1] strspn -> 1346
> [2] strcspn -> 1193
> [3] strpbrk -> 1533
> compared to
> [4] strchr -> 24444
> I would say it's not worth the trouble of changing the standard
> (via aliases, new functions, or renamings).
>
> streq was good. strnul was good. But that does not mean that every
> new function in this area will be as good.
While I'm okay not renaming strpbrk(3), I still think the stp[c]spn()
variants of str[c]spn(3) would be good.
str[c]spn(3) are not commonly used, but I see many cases of code doing
manual loops and byte operations of what would be str[c]spn(3).
I suspect many programmers don't know this sub-family of string
functions. But that could change. I'm replacing code in some projects
to start using them more.
In shadow utils, in a branch where I've replaced many of those, I've
found that st[rp]spn() are way more useful than strchr(3):
$ grep -rn 'strchr *(' | wc -l
14
$ grep -rn 'st[pr]spn *(' | wc -l
65
Have a lovely night!
Alex
>
> Bruno
>
> [1] https://codesearch.debian.net/search?q=strspn+%28&literal=1
> [2] https://codesearch.debian.net/search?q=strcspn+%28&literal=1
> [3] https://codesearch.debian.net/search?q=strpbrk+%28&literal=1
> [4] https://codesearch.debian.net/search?q=strchr+%28&literal=1
>
>
>
--
<https://www.alejandro-colomar.es>
signature.asc
Description: PGP signature
