aboutsummaryrefslogtreecommitdiffstats
path: root/strcasechr.c
blob: 83e8f738ec453279627a6d7cc59dbb366e3e2c24 (plain) (blame)
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
31
32
33
34
35
36
37
38
39
40
41
/* See LICENSE file for copyright and license details. */
#include "libsimple.h"
#ifndef TEST


char *
libsimple_strcasechr(const char *s_, int c)
{
	char *s = *(char **)(void *)&s_, lc = (char)tolower(c), uc = (char)toupper(c);
	if (lc != uc)
		for (; *s && *s != lc && *s != uc; s++);
	else
		for (; *s && *s != lc; s++);
	return *s ? s : NULL;
}


#else
#include "test.h"

int
main(void)
{
	assert(!strcmpnul(libsimple_strcasechr("abcABCabcABCx123123", 'c'), "cABCabcABCx123123"));
	assert(!strcmpnul(libsimple_strcasechr("abcABCabcABCx123123", 'a'), "abcABCabcABCx123123"));
	assert(!strcmpnul(libsimple_strcasechr("abcABCabcABCx123123", 'x'), "x123123"));
	assert(!strcmpnul(libsimple_strcasechr("abcABCabcABCx123123", 'C'), "cABCabcABCx123123"));
	assert(!strcmpnul(libsimple_strcasechr("abcABCabcABCx123123", 'A'), "abcABCabcABCx123123"));
	assert(!strcmpnul(libsimple_strcasechr("abcABCabcABCx123123", 'X'), "x123123"));
	assert(!strcmpnul(libsimple_strcasechr("ABCabcABCabcX123123", 'c'), "CabcABCabcX123123"));
	assert(!strcmpnul(libsimple_strcasechr("ABCabcABCabcX123123", 'a'), "ABCabcABCabcX123123"));
	assert(!strcmpnul(libsimple_strcasechr("ABCabcABCabcX123123", 'x'), "X123123"));
	assert(!strcmpnul(libsimple_strcasechr("ABCabcABCabcX123123", 'C'), "CabcABCabcX123123"));
	assert(!strcmpnul(libsimple_strcasechr("ABCabcABCabcX123123", 'A'), "ABCabcABCabcX123123"));
	assert(!strcmpnul(libsimple_strcasechr("ABCabcABCabcX123123", 'X'), "X123123"));
	assert(!libsimple_strcasechr("ABCabcABCabcX123123", '0'));
	assert(!strcmpnul(libsimple_strcasechr("ABCabcABCabcX123123", '1'), "123123"));
	return 0;
}

#endif