On 2025-09-18 18:10, Alejandro Colomar wrote:
My original proposal wasstrprefix(), stpprefix() strsuffix(), stpsuffix()
There is a tension between following the standard naming conventions (str[a-z]*, mem[a-z]*) and having readable names. I expect the C committee would look with more favor on names that follow existing naming conventions, even if they're a bit less readable.
Gnulib already has names str_startswith and str_endswith for the boolean flavors. Perhaps we can add just the pointer flavors, and use more-standardish names. strprefix and strsuffix are reasonably easy to read and understand; stpprefix and stpsuffix less so. So one possibility is to implement strprefix and strsuffix in Gnulib, using a pointer API.
The classic problem with a pointer API, though, is that it's not polymorphic. strchr, for example, accepts char const * but returns char * and that is a pain. We could work around this problem by having strprefix and strsuffix return a length rather than a pointer. But perhaps I'm starting to bikeshed too much here.
