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

Alejandro Colomar via Mutt-dev <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <aZZeW3cd7YkEr4lu@devuan>
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);

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>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmmWXukACgkQ64mZXMKQ
wqnFgg//bu3IPzyplq/MUz8fcdwGSbheUoL/8TSr5znxrGdrlvFw0m2ZtDFYTQxW
sIy54pz2yyoSrM16mZxkC9FHnHuuQAH3mEk+HsT0iSTo7YTg3N9mFvvxtSVGRlcb
zPw0c1Yk+GfMlMxsdnnD3nB4ybpNP8jGaMoQhv5v88FEOn2vV9//v7jSe/iUzuqJ
a17pTqORA6b2MkTWNxA4txcnzfFqbTJUTlQwGl2c8BzKDbmuk215kd6F6LkOQ+PS
WxHOZi9aS0XYG6l9CKRe25HYK7ILmkNYeGPMsGSa6U4dxnYpBrjaYMQMdyQyiT6u
zEM07EfleSzHEimSPupGkffjThJ+2k1yo3DZkMN2DwhQ/SYY/CpGHlmApEzQIati
aHsgrct/ZZIAEdAl08I7GlpQMwUhu9eTJfWCwcH9wptxbxmHZIK0ExdBgr1nXwyp
w1s5HWK188lj21ZmDMKkWIagocxndAF5mlSnU4rHy6+Lhs+Xz5CE52Rfv3ux63Fm
jLbOg7fDzpe62dUjddKzFbQUTPNdBUzcwyCkOqNjEJXlKD4Td+93sU6IUMoHDxYo
KNN1bzEZhZ+YS4l1lHXsW7SXAyH5SPX0vqUiQlXhZ+Qp+7Q9H20BgRMxAd7Etta8
Kb0Py17dH5jGcHDPTeHNLryEahm9zXVuZr9Tc2VSn8ykR89CBcI=
=ak2C
-----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.