From 75f33081c2ec372f1e729562aa1120b3d2e8062c Mon Sep 17 00:00:00 2001 From: Jasper Verschueren Date: Tue, 4 Dec 2018 14:52:22 +0100 Subject: [PATCH] DEF: added lwip_strnistr() for case insensitive matching --- src/core/def.c | 23 +++++++++++++++++++++++ src/include/lwip/def.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/src/core/def.c b/src/core/def.c index 9da36fee..282fb41d 100644 --- a/src/core/def.c +++ b/src/core/def.c @@ -118,6 +118,29 @@ lwip_strnstr(const char *buffer, const char *token, size_t n) } #endif +#ifndef lwip_strnistr +/** + * @ingroup sys_nonstandard + * lwIP default implementation for strnistr() non-standard function. + * This can be \#defined to strnistr() depending on your platform port. + */ +char * +lwip_strnistr(const char *buffer, const char *token, size_t n) +{ + const char *p; + size_t tokenlen = strlen(token); + if (tokenlen == 0) { + return LWIP_CONST_CAST(char *, buffer); + } + for (p = buffer; *p && (p + tokenlen <= buffer + n); p++) { + if (lwip_strnicmp(p, token, tokenlen) == 0) { + return LWIP_CONST_CAST(char *, p); + } + } + return NULL; +} +#endif + #ifndef lwip_stricmp /** * @ingroup sys_nonstandard diff --git a/src/include/lwip/def.h b/src/include/lwip/def.h index dfb266d1..d6bf7630 100644 --- a/src/include/lwip/def.h +++ b/src/include/lwip/def.h @@ -144,6 +144,10 @@ int lwip_stricmp(const char* str1, const char* str2); /* This can be #defined to strnstr() depending on your platform */ char* lwip_strnstr(const char* buffer, const char* token, size_t n); #endif +#ifndef lwip_strnistr +/* This can be #defined to strnistr() depending on your platform */ +char* lwip_strnistr(const char* buffer, const char* token, size_t n); +#endif #ifdef __cplusplus }