diff options
author | Mattias Andrée <maandree@kth.se> | 2018-10-21 20:12:31 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2018-10-21 20:12:31 +0200 |
commit | 2215a474e340c3f8f58efe35fc96d62693eacef7 (patch) | |
tree | 87505305fb28e285b02082f07cdb2760b53ff01d /memcaseends.c | |
parent | Add memcasechr (diff) | |
download | libsimple-2215a474e340c3f8f58efe35fc96d62693eacef7.tar.gz libsimple-2215a474e340c3f8f58efe35fc96d62693eacef7.tar.bz2 libsimple-2215a474e340c3f8f58efe35fc96d62693eacef7.tar.xz |
Add memcase{cmp,ends,starts,eq} and mem[r]casemem
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | memcaseends.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/memcaseends.c b/memcaseends.c new file mode 100644 index 0000000..0a673f7 --- /dev/null +++ b/memcaseends.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +int +libsimple_memcaseends(const void *s_, size_t n, const void *t_, size_t m) +{ + const char *s = s_, *t = t_; + if (n < m) + return 0; + while (n--, m--) + if (tolower(s[n]) != tolower(t[m])) + return 0; + return 1; +} + + +#else +#include "test.h" + +int +main(void) +{ + assert(libsimple_memcaseends("", 0, "", 0) == 1); + assert(libsimple_memcaseends("test", 4, "", 0) == 1); + assert(libsimple_memcaseends("", 0, "test", 4) == 0); + assert(libsimple_memcaseends("test", 4, "test", 4) == 1); + assert(libsimple_memcaseends("test", 4, "test", 5) == 0); + assert(libsimple_memcaseends("test", 4, "testx", 5) == 0); + assert(libsimple_memcaseends("test", 4, "est", 3) == 1); + assert(libsimple_memcaseends("test", 4, "st", 2) == 1); + assert(libsimple_memcaseends("test", 4, "t", 1) == 1); + assert(libsimple_memcaseends("test", 4, "x", 1) == 0); + assert(libsimple_memcaseends("test", 4, "xx", 2) == 0); + + assert(libsimple_memcaseends("TEST", 4, "", 0) == 1); + assert(libsimple_memcaseends("TEST", 4, "test", 4) == 1); + assert(libsimple_memcaseends("TEST", 4, "test", 5) == 0); + assert(libsimple_memcaseends("TEST", 4, "testx", 5) == 0); + assert(libsimple_memcaseends("TEST", 4, "est", 3) == 1); + assert(libsimple_memcaseends("TEST", 4, "st", 2) == 1); + assert(libsimple_memcaseends("TEST", 4, "t", 1) == 1); + assert(libsimple_memcaseends("TEST", 4, "x", 1) == 0); + assert(libsimple_memcaseends("TEST", 4, "xx", 2) == 0); + + assert(libsimple_memcaseends("", 0, "TEST", 4) == 0); + assert(libsimple_memcaseends("test", 4, "TEST", 4) == 1); + assert(libsimple_memcaseends("test", 4, "TEST", 5) == 0); + assert(libsimple_memcaseends("test", 4, "TESTX", 5) == 0); + assert(libsimple_memcaseends("test", 4, "EST", 3) == 1); + assert(libsimple_memcaseends("test", 4, "ST", 2) == 1); + assert(libsimple_memcaseends("test", 4, "T", 1) == 1); + assert(libsimple_memcaseends("test", 4, "X", 1) == 0); + assert(libsimple_memcaseends("test", 4, "XX", 2) == 0); + return 0; +} + +#endif |