Re: [PATCH] wip: change ISSPACE to use ascii whitespace check.

Alejandro Colomar via Mutt-dev <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <aZZfpAyx-oOoNnrs@devuan>
On 2026-02-19T01:53:01+0100, Alejandro Colomar wrote:
> On 2026-02-18T23:21:34+0100, Alejandro Colomar wrote:
> > Hi Crystal,
> > 
> > On 2026-02-18T21:58:24+0000, Crystal Kolipe via Mutt-dev wrote:
> > > On Wed, Feb 18, 2026 at 03:29:57PM +0100, Alejandro Colomar via Mutt-dev wrote:
> > > > BTW, with the macros shown above, one could implement:
> > > > 
> > > > 	#define streq(a,b)  (strcmp(a,b) == 0)
> > > > 
> > > > 	#define isspace_c(c)            (!streq(strchrnul(MUTT_CTYPE_SPACE_C, c), ""))
> > > > 	#define isspace_rfc5322_fws(c)  (!streq(strchrnul(MUTT_CTYPE_RFC5322_FWS, c), ""))
> > > > 
> > > > Although, in general, using the strspn(3) family of functions directly
> > > > seems more ergonomic.
> > > 
> > > Note that strchrnul() is not available natively on OpenBSD.
> > 
> > D'oh!  Well, I guess we could add it as a fallback there.
> > I hope POSIX takes this API eventually.
> > 
> > Here's a naive definition:
> > 
> > 	char *
> > 	strchrnul(const char *s, int c)
> > 	{
> > 		char  *p;
> > 
> > 		p = strchr(s, c);
> > 		if (p == NULL)
> > 			return (char *) s + strlen(s);
> > 		return p;
> 
> This can be compacted into a one-liner:
> 
> 		return strchr(s, c) ?: (char *) s + strlen(s);

And avoiding the cast:

	#define strnul(s)  strchr(s, '\0')

	char *
	strchrnul(const char *s, int c)
	{
		return strchr(s, c) ?: strnul(s);
	}

> 
> All compilers that I know, support '?:'.  It will be discussed for
> standardization next month.
> 
> > 	}
> > 
> > Here's another one, which might be more or less readable:
> > 
> > 	char *
> > 	strchrnul(const char *s, int c)
> > 	{
> > 		char  r[2] = {c, '\0'};
> > 
> > 		return (char *) s + strcspn(s, r);
> > 	}
> > 
> > Disclaimer: I haven't tested these yet.
> > 
> > 
> > Have a lovely night!
> > Alex
> > 
> > -- 
> > <https://www.alejandro-colomar.es>
> 
> 
> 
> -- 
> <https://www.alejandro-colomar.es>



-- 
<https://www.alejandro-colomar.es>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmmWX+cACgkQ64mZXMKQ
wqnG6g/+Lh+Nr34aywitYUE8uiGqSLiDfxq/+2jn5FLcrUHHY8AAF0ZvVxi9ETiH
2PLbn7TiCpTb/P1EuYenFmSgQXbEIYgNEc4ARs7MS7OGt+rqWc/g5W2QHeMtpex6
WfQxbPUVHvgq+/oU1lpZNFKesTtUubUoJK5pdXxLqJvEFA5z8C3vO0cRPRpdBbqP
Rhvp9/Q+qTXSmqVyzPEiYdif4ViVuQyDYPLiTGxhoruQ7Id0J0W7iS8ZwLK0E7SX
GHDlHnSbDUrR3Z5MaX7F2nkQBWW7ifyKFJy3nfLUCPo1dgIKyfV8mTeejibHrNM4
LK0j+1X6p61aKYhIGkvr43XZidK32MWOqwcWXDy1lkgX77OCM0ZLQXqG8t22HzXN
l5Db3iZ7yUKe410kdd6hnRBogpKLfMmxnV0lDkauBK3Qyr8aSH4w3ayGzWy5Z7bm
eCiTzTASiCAu7AUCDVFwxcxK+DTg9oOoyJRw8quF4O4olQH+Crxxo0fcsvxOzDcc
iWJEp2/CGup0ultXoJuvNRGmPAlB4mGM8e9F4XFjqPGOuRJ0uOem9IlPcELxJbUy
YqAn8W85WQzrLXfQ3xyXmg6+gUaz0HZi0sye1glyjZTvVgaiiYyF/j8aiIKKiuYB
vY1y0xX0gkmzS+pJ7iqnBYwom0S48a9t7B5RqS4GvX0k97Umupg=
=R7sp
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.