aboutsummaryrefslogtreecommitdiffstats
path: root/strrstr.c
blob: 5d647448a0ad9d7f90425363223149cb2ae3b07b (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* See LICENSE file for copyright and license details. */
#include "libsimple.h"


char *
libsimple_strrstr(const char *hay, const char *sub)
{
	return libsimple_memrmem(hay, strlen(hay), sub, strlen(sub));
}


#ifdef TEST
#include <assert.h>

int
main(void)
{
	assert(!strcmp(libsimple_strrstr("test", "test"), "test"));
	assert(!strcmp(libsimple_strrstr("", ""), ""));
	assert(!strcmp(libsimple_strrstr("test", ""), ""));
	assert(!libsimple_strrstr("", "test"));
	assert(!libsimple_strrstr("t", "test"));
	assert(!strcmp(libsimple_strrstr("test", "t"), "t"));
	assert(!strcmp(libsimple_strrstr("test", "e"), "est"));
	assert(!strcmp(libsimple_strrstr("test", "s"), "st"));
	assert(!libsimple_strrstr("test", "x"));
	assert(!strcmp(libsimple_strrstr("test", "te"), "test"));
	assert(!strcmp(libsimple_strrstr("test", "es"), "est"));
	assert(!strcmp(libsimple_strrstr("test", "st"), "st"));
	assert(!libsimple_strrstr("test", "xx"));
	assert(!strcmp(libsimple_strrstr("abc", "c"), "c"));
	assert(!strcmp(libsimple_strrstr("abc", "bc"), "bc"));
	assert(!strcmp(libsimple_strrstr("abc", "abc"), "abc"));
	assert(!strcmp(libsimple_strrstr("abcabc", "bc"), "bc"));

	assert(!strcmp(libsimple_strrcasestr("TEST", "test"), "TEST"));
	assert(!strcmp(libsimple_strrcasestr("TEST", ""), ""));
	assert(!libsimple_strrcasestr("T", "test"));
	assert(!strcmp(libsimple_strrcasestr("TEST", "t"), "T"));
	assert(!strcmp(libsimple_strrcasestr("TEST", "e"), "EST"));
	assert(!strcmp(libsimple_strrcasestr("TEST", "s"), "ST"));
	assert(!libsimple_strrcasestr("TEST", "x"));
	assert(!strcmp(libsimple_strrcasestr("TEST", "te"), "TEST"));
	assert(!strcmp(libsimple_strrcasestr("TEST", "es"), "EST"));
	assert(!strcmp(libsimple_strrcasestr("TEST", "st"), "ST"));
	assert(!libsimple_strrcasestr("TEST", "xx"));
	assert(!strcmp(libsimple_strrcasestr("ABC", "c"), "C"));
	assert(!strcmp(libsimple_strrcasestr("ABC", "bc"), "BC"));
	assert(!strcmp(libsimple_strrcasestr("ABC", "abc"), "ABC"));
	assert(!strcmp(libsimple_strrcasestr("ABCABC", "bc"), "BC"));

	assert(!strcmp(libsimple_strrcasestr("test", "TEST"), "test"));
	assert(!libsimple_strrcasestr("", "TEST"));
	assert(!libsimple_strrcasestr("t", "TEST"));
	assert(!strcmp(libsimple_strrcasestr("test", "T"), "t"));
	assert(!strcmp(libsimple_strrcasestr("test", "E"), "est"));
	assert(!strcmp(libsimple_strrcasestr("test", "S"), "st"));
	assert(!libsimple_strrcasestr("test", "X"));
	assert(!strcmp(libsimple_strrcasestr("test", "TE"), "test"));
	assert(!strcmp(libsimple_strrcasestr("test", "ES"), "est"));
	assert(!strcmp(libsimple_strrcasestr("test", "ST"), "st"));
	assert(!libsimple_strrcasestr("test", "XX"));
	assert(!strcmp(libsimple_strrcasestr("abc", "C"), "c"));
	assert(!strcmp(libsimple_strrcasestr("abc", "BC"), "bc"));
	assert(!strcmp(libsimple_strrcasestr("abc", "ABC"), "abc"));
	assert(!strcmp(libsimple_strrcasestr("abcabc", "BC"), "bc"));
	return 0;
}

#endif