Hi Collin,

On Wed, Sep 17, 2025 at 01:43:10AM -0700, Collin Funk wrote:
> Alejandro Colomar <[email protected]> writes:
> 
> >> As Gnulib already has a streq module with different meaning, I named the 
> >> new
> >> module "stringeq"; it implements both streq and memeq in <string.h>. There
> >> seemed little point to having a separate module per function.
> >
> > Maybe it would be good to call the module just 'string' so that we can
> > add more functions to it?  I have a list of other similar functions that
> > I'm proposing for standardization.  A few obvious ones are:
> 
> The string module exists as an alias to string-h. We unified the naming
> conventions for headers a few months ago [1].

Hmm.  Maybe we could include these functions in the string-h module?

> > <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3612.txt>
> > strpfx() - string prefix (returns boolean, for compatibility with streq)
> > stppfx() - string prefix (returns pointer)
> >
> > <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3613.txt>
> > strsfx() - string suffix (returns boolean, for compatibility with streq)
> > stpsfx() - string suffix (returns pointer)
> 
> We have str_startswith() and str_endswith() already for this.

There's a problem with str_startswith(): It only returns a boolean.
I have many use cases where I need a pointer to the end of the prefix.
It allows jumping over the prefix.  Here's one example that I use in
shadow utils (currently, you'll find it as strprefix(); we're in the
process of renaming it):

        tty = stppfx(tty, "/dev/") ?: tty;

> I prefer
> those names personally. But I don't like many of the string.h names we
> are stuck with (e.g. strspn, strcspn), so maybe it is a me problem. :)

:)

The <string.h> names are a bit cryptic, and some of them could be
better (e.g., strpbrk(3) should have been called strchrs()), but they
are quite consistent, and I like that.  They have names that --once you
grok the conventions-- tell a lot of information in very little space.


Cheers,
Alex

> 
> Collin
> 
> [1] 
> https://github.com/coreutils/gnulib/blob/c172e838f939f7c97daed1a80a7ec3479b4c43c6/modules/string

-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature

Reply via email to