str_extra.c

Extra string functions library for C
git clone git://git.finwo.net/lib/str_extra.c
Log | Files | Refs | README

commit 2d6741e2c5fa76fd4509c6b16c3172a4a71130b6
parent a040f28b4a899e87e419d7df9ce467f7617a3d80
Author: finwo <finwo@pm.me>
Date:   Tue, 12 Aug 2025 15:40:49 +0200

Add strcasecmp

Diffstat:
Msrc/str_extra.h | 1+
Asrc/strcasecmp.c | 26++++++++++++++++++++++++++
Asrc/strcasecmp.h | 18++++++++++++++++++
3 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/src/str_extra.h b/src/str_extra.h @@ -4,5 +4,6 @@ #include "str_isHex.h" #include "strnstr.h" #include "strtoupper.h" +#include "strcasecmp.h" #endif // __FINWO_STREXTRA_H__ diff --git a/src/strcasecmp.c b/src/strcasecmp.c @@ -0,0 +1,26 @@ +#ifdef __cplusplus +extern "C" { +#endif + +#include "strcasecmp.h" + +#if defined(_WIN32) || defined(_WIN64) + +int strcasecmp(const char *a, const char *b) { + int ca, cb; + do { + // Different diacritic options with upper and lower, so merge with both + ca = tolower(toupper(*(unsigned char *)a)); + cb = tolower(toupper(*(unsigned char *)b)); + a++; + b++; + } while(ca == cb && ca != '\0'); + return ca - cb; +} + +#endif + + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/src/strcasecmp.h b/src/strcasecmp.h @@ -0,0 +1,18 @@ +#ifndef __FINWO_STREXTRA_STRCASECMP_H__ +#define __FINWO_STREXTRA_STRCASECMP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) || defined(_WIN64) +int strcasecmp(const char *a, const char *b); +#else +#include <strings.h> +#endif + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __FINWO_STREXTRA_STRCASECMP_H__