From e690b3f3dd296c4ff4740a6361eadb2b8a6ce396 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sun, 4 Oct 2020 03:45:29 +0200 Subject: [PATCH] Add string_tolower() --- miscutil.c | 37 +++++++++++++++++++++++++++++++++++++ miscutil.h | 1 + 2 files changed, 38 insertions(+) diff --git a/miscutil.c b/miscutil.c index 499579f7..9d1226b5 100644 --- a/miscutil.c +++ b/miscutil.c @@ -560,6 +560,43 @@ char *string_toupper(const char *string) } +/********************************************************************* + * + * Function : string_tolower + * + * Description : Produce a copy of string with all convertible + * characters converted to lowercase. + * + * Parameters : + * 1 : string = string to convert + * + * Returns : Lowercase copy of string if possible, + * NULL on out-of-memory or if string was NULL. + * + *********************************************************************/ +char *string_tolower(const char *string) +{ + char *result, *p; + const char *q; + + if (!string || ((result = (char *)zalloc(strlen(string) + 1)) == NULL)) + { + return NULL; + } + + q = string; + p = result; + + while (*q != '\0') + { + *p++ = (char)privoxy_tolower(*q++); + } + + return result; + +} + + /********************************************************************* * * Function : string_move diff --git a/miscutil.h b/miscutil.h index 04050f01..7c5f7dff 100644 --- a/miscutil.h +++ b/miscutil.h @@ -61,6 +61,7 @@ extern int strncmpic(const char *s1, const char *s2, size_t n); extern jb_err string_append(char **target_string, const char *text_to_append); extern jb_err string_join (char **target_string, char *text_to_append); extern char *string_toupper(const char *string); +extern char *string_tolower(const char *string); extern void string_move(char *dst, char *src); extern char *chomp(char *string); -- 2.39.2