#define BITOP(a,b,op) \
((a)[(gsize)(b)/(8*sizeof *(a))] op (gsize)1<<((gsize)(b)%(8*sizeof *(a))))
+
+
gsize
rspamd_memcspn (const gchar *s, const gchar *e, gsize len)
{
gsize byteset[32 / sizeof(gsize)];
const gchar *p = s, *end = s + len;
+ if (!e[1]) {
+ for (; *p != *e; p++);
+ return p - s;
+ }
+
memset (byteset, 0, sizeof byteset);
for (; *e && BITOP (byteset, *(guchar *)e, |=); e++);
return p - s;
}
+gsize
+rspamd_memspn (const gchar *s, const gchar *e, gsize len)
+{
+ gsize byteset[32 / sizeof(gsize)];
+ const gchar *p = s, *end = s + len;
+
+ if (!e[1]) {
+ for (; *p == *e; p++);
+ return p - s;
+ }
+
+ memset (byteset, 0, sizeof byteset);
+
+ for (; *e && BITOP (byteset, *(guchar *)e, |=); e++);
+ for (; p < end && BITOP (byteset, *(guchar *)p, &); p++);
+
+ return p - s;
+}
+
gssize
rspamd_decode_qp2047_buf (const gchar *in, gsize inlen,
gchar *out, gsize outlen)
*/
gsize rspamd_memcspn (const gchar *s, const gchar *e, gsize len);
+/**
+ * Return length of memory segment starting in `s` that contains only chars from `e`
+ * @param s any input
+ * @param e zero terminated string of inclusions
+ * @param len length of `s`
+ * @return segment size
+ */
+gsize rspamd_memspn (const gchar *s, const gchar *e, gsize len);
/* https://graphics.stanford.edu/~seander/bithacks.html#HasMoreInWord */
#define rspamd_str_hasmore(x,n) ((((x)+~0UL/255*(127-(n)))|(x))&~0UL/255*128)