/* This file is part of limb https://lila.oss/limb
* Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */
/* SPDX-License-Identifier: GPL-2.0-only */
#include <ctype.h>
#include <limb/bytestr.h>
size_t
byte_istr(const char *haystack, size_t hlen, const char *needle, size_t nlen)
{
if (!hlen || !nlen || nlen > hlen) return hlen;
size_t from, n;
for (from = 0, n = 0; from < hlen - nlen && n < nlen; ) {
if (tolower(haystack[from + n]) != tolower(needle[n])) {
n = 0;
++from;
} else {
++n;
}
}
return (n == nlen) ? from : hlen;
}