aboutsummaryrefslogtreecommitdiffstats
path: root/strrncasestr.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-19 00:27:04 +0200
committerMattias Andrée <maandree@kth.se>2018-08-19 00:27:04 +0200
commitbf3440c6c9a26644d77d2ebf0d24ac1583588ab7 (patch)
tree9b55597e3456efb17512c3cb8d3e250334d994b9 /strrncasestr.c
parentFix and run tests (diff)
downloadlibsimple-bf3440c6c9a26644d77d2ebf0d24ac1583588ab7.tar.gz
libsimple-bf3440c6c9a26644d77d2ebf0d24ac1583588ab7.tar.bz2
libsimple-bf3440c6c9a26644d77d2ebf0d24ac1583588ab7.tar.xz
Add str[r]n[case]str and str[n][case]cmpnul
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--strrncasestr.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/strrncasestr.c b/strrncasestr.c
new file mode 100644
index 0000000..8fb0778
--- /dev/null
+++ b/strrncasestr.c
@@ -0,0 +1,23 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+
+
+char *
+libsimple_strrncasestr(const char *h_, const char *n, size_t len)
+{
+ char *h = *(char **)(void *)&h_;
+ size_t hn = strlen(h);
+ size_t nn = strlen(n);
+ hn = MIN(hn, len);
+ nn = MIN(nn, len);
+ if (!nn)
+ return &h[hn];
+ if (hn < nn)
+ return NULL;
+ for (h += hn -= nn; hn--; h--)
+ if (!strncasecmp(h, n, nn))
+ return h;
+ if (!strncasecmp(h, n, nn))
+ return h;
+ return NULL;
+}