summaryrefslogtreecommitdiffstats
path: root/usr/klibc/strxspn.c
blob: 99bdbffb1285c384f093faf83715e68bc90e80b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * strpbrk
 */

#include <string.h>
#include <stddef.h>
#include <inttypes.h>
#include <limits.h>
#include "strxspn.h"

size_t __strxspn(const char *s, const char *map, int parity)
{
	char matchmap[UCHAR_MAX + 1];
	size_t n = 0;

	/* Create bitmap */
	memset(matchmap, 0, sizeof matchmap);
	while (*map)
		matchmap[(unsigned char)*map++] = 1;

	/* Make sure the null character never matches */
	matchmap[0] = parity;

	/* Calculate span length */
	while (matchmap[(unsigned char)*s++] ^ parity)
		n++;

	return n;
}