aboutsummaryrefslogtreecommitdiffstats
path: root/strcaseends.c
blob: 6ff9d8b3d304d16be8982570529bbbe09711dfb6 (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
42
43
44
45
46
47
48
49
50
51
52
53
/* See LICENSE file for copyright and license details. */
#include "libsimple.h"


int
libsimple_strcaseends(const char *s, const char *t)
{
	size_t sn = strlen(s);
	size_t tn = strlen(t);
	if (tn > sn)
		return 0;
	return !strcasecmp(&s[sn - tn], t);
}


#ifdef TEST
#include <assert.h>

int
main(void)
{
	assert(libsimple_strcaseends("", "") == 1);
	assert(libsimple_strcaseends("test", "") == 1);
	assert(libsimple_strcaseends("", "test") == 0);
	assert(libsimple_strcaseends("test", "test") == 1);
	assert(libsimple_strcaseends("test", "testx") == 0);
	assert(libsimple_strcaseends("test", "est") == 1);
	assert(libsimple_strcaseends("test", "st") == 1);
	assert(libsimple_strcaseends("test", "t") == 1);
	assert(libsimple_strcaseends("test", "x") == 0);
	assert(libsimple_strcaseends("test", "xx") == 0);

	assert(libsimple_strcaseends("TEST", "") == 1);
	assert(libsimple_strcaseends("TEST", "test") == 1);
	assert(libsimple_strcaseends("TEST", "testx") == 0);
	assert(libsimple_strcaseends("TEST", "est") == 1);
	assert(libsimple_strcaseends("TEST", "st") == 1);
	assert(libsimple_strcaseends("TEST", "t") == 1);
	assert(libsimple_strcaseends("TEST", "x") == 0);
	assert(libsimple_strcaseends("TEST", "xx") == 0);

	assert(libsimple_strcaseends("", "TEST") == 0);
	assert(libsimple_strcaseends("test", "TEST") == 1);
	assert(libsimple_strcaseends("test", "TESTX") == 0);
	assert(libsimple_strcaseends("test", "EST") == 1);
	assert(libsimple_strcaseends("test", "ST") == 1);
	assert(libsimple_strcaseends("test", "T") == 1);
	assert(libsimple_strcaseends("test", "X") == 0);
	assert(libsimple_strcaseends("test", "XX") == 0);
	return 0;
}

#endif