summaryrefslogtreecommitdiff
path: root/src/string/strcspn.c
blob: 58d3f33bb0e7067b46c47f50c184d70ccdf517ae (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
30
#include <string.h>
#include "_assert.h"

/** count non-matching characters **/

size_t strcspn(const char *s1, const char *s2)
{
	size_t i = 0;

	ASSERT_NONNULL(s1);
	ASSERT_NONNULL(s2);

	for (i = 0; s1[i] != '\0'; i++) {
		if (strchr (s2, s1[i]) != NULL) {
			break;
		}
	}

	return i;
}

/***
the number of characters that the beginning of
the string ARGUMENT(s1) that are not in the string ARGUMENT(s2).
***/

/*
RETURN_ALWAYS(the number of non-matching characters);
STDC(1)
*/