diff options
author | Mattias Andrée <maandree@kth.se> | 2018-10-21 11:51:38 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2018-10-21 11:51:38 +0200 |
commit | 160eaaddcfed8075abd06624835a2d49548eb5de (patch) | |
tree | 6883e07688ad43520b7407d2728f41d0cf9c68a9 /strcasechrnul.c | |
parent | Add man pages for more str-functions (diff) | |
download | libsimple-160eaaddcfed8075abd06624835a2d49548eb5de.tar.gz libsimple-160eaaddcfed8075abd06624835a2d49548eb5de.tar.bz2 libsimple-160eaaddcfed8075abd06624835a2d49548eb5de.tar.xz |
Add strcasechr and strcasechrnul
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'strcasechrnul.c')
-rw-r--r-- | strcasechrnul.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/strcasechrnul.c b/strcasechrnul.c new file mode 100644 index 0000000..5afcd54 --- /dev/null +++ b/strcasechrnul.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +char * +libsimple_strcasechrnul(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; +} + + +#else +#include "test.h" + +int +main(void) +{ + assert(!strcmpnul(libsimple_strcasechrnul("abcABCabcABCx123123", 'c'), "cABCabcABCx123123")); + assert(!strcmpnul(libsimple_strcasechrnul("abcABCabcABCx123123", 'a'), "abcABCabcABCx123123")); + assert(!strcmpnul(libsimple_strcasechrnul("abcABCabcABCx123123", 'x'), "x123123")); + assert(!strcmpnul(libsimple_strcasechrnul("abcABCabcABCx123123", 'C'), "cABCabcABCx123123")); + assert(!strcmpnul(libsimple_strcasechrnul("abcABCabcABCx123123", 'A'), "abcABCabcABCx123123")); + assert(!strcmpnul(libsimple_strcasechrnul("abcABCabcABCx123123", 'X'), "x123123")); + assert(!strcmpnul(libsimple_strcasechrnul("ABCabcABCabcX123123", 'c'), "CabcABCabcX123123")); + assert(!strcmpnul(libsimple_strcasechrnul("ABCabcABCabcX123123", 'a'), "ABCabcABCabcX123123")); + assert(!strcmpnul(libsimple_strcasechrnul("ABCabcABCabcX123123", 'x'), "X123123")); + assert(!strcmpnul(libsimple_strcasechrnul("ABCabcABCabcX123123", 'C'), "CabcABCabcX123123")); + assert(!strcmpnul(libsimple_strcasechrnul("ABCabcABCabcX123123", 'A'), "ABCabcABCabcX123123")); + assert(!strcmpnul(libsimple_strcasechrnul("ABCabcABCabcX123123", 'X'), "X123123")); + assert(!strcmpnul(libsimple_strcasechrnul("ABCabcABCabcX123123", '0'), "")); + assert(!strcmpnul(libsimple_strcasechrnul("ABCabcABCabcX123123", '1'), "123123")); + return 0; +} + +#endif |