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

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

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

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmmWO2UACgkQ64mZXMKQ
wqlIbhAAnk9OkbqCJWaa4auegyareRAaRm00UwIJTMs4zEoWuAILgv/+a3K3MAWf
i9urDFXHx/s8ttXkhN5ZAJEg34krYK/KXhwUdEA2I/cuquvUZTKP4oKHOnalRjOY
sbEQ6HSgXtLjvD7pWXX/x/hsB8gtVw+0YNCe+oSiGr52vzW9N3mwSRcztRJsane0
hGZoqlEF3bTe/Zgh1ELAd6sT+iU0GFU6bc5O4YjV/zg1ZDIVxT722g8UtXQ7S8Eh
63CWg66EVJYq4pCIuqxYt41vpx4U9ra9K1s2F1mvfk5bTFr7UlRzkdEgQf7VrcWP
taVPfZV/Yrk3dA1hRd4HaOaIx/hsVKWfg/I4nytxtdTpZXzd7ECe9tbkfNJpukIp
ZlkLaV+lNpH+Yahom3fAFtdJ6qkU61H9ADtj9HVlH3DPPraEKJPr1tcpxUMMwcvi
90eFGPFoPvE/71qZLN0c6pXx5YIg8DkbW8xVG5hvKf02wj28olW9XjHDXRRiGVFY
shWQfD5xCNkuL2XkaK09j6j5ZlR3M7c7Z9paG7r8GxS3zd2e/VT1fS8+nThUIWO5
HalBkzsc/HJD5JS9eALtYOVbJ3KnPsJ8Nfg7MDiTVrIHjAvDdmcyjokO157iBvm+
84nT1xwWsNbmr8wXw85b3m8fdNTsywpgYuaEIFR+vPOc+1fJPH0=
=wEiv
-----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.