libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 0469d08820522ca62916c5f963d12f256c270608
parent 84b915ce29e87b5e0ff08825182e064e59e77e7d
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Thu, 18 Dec 2025 15:52:45 +0100

mhd_str: added mhd_str_to_uppercase_bin_n()

Diffstat:
Msrc/mhd2/mhd_str.c | 35++++++++++++++++++++++++++++-------
Msrc/mhd2/mhd_str.h | 24++++++++++++++++++++++++
2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/src/mhd2/mhd_str.c b/src/mhd2/mhd_str.c @@ -74,7 +74,7 @@ #ifdef HAVE_INLINE_FUNCS -#if 0 /* Disable unused functions. */ +#ifdef mhd_HAVE_STR_TO_UPPER /** * Check whether character is lower case letter in US-ASCII * @@ -84,11 +84,13 @@ mhd_static_inline MHD_FN_CONST_ bool isasciilower (char c) { - return (c >= 'a') && (c <= 'z'); + const unsigned int uc = (unsigned int) (unsigned char) c; + const unsigned int t = uc - (unsigned int) (unsigned char) 'a'; + return (((unsigned int) ('z' - 'a')) >= t); } -#endif /* Disable unused functions. */ +#endif /* mhd_HAVE_STR_TO_UPPER */ /** @@ -183,12 +185,12 @@ toasciilower (char c) } -#if 0 /* Disable unused functions. */ +#ifdef mhd_HAVE_STR_TO_UPPER /** * Convert US-ASCII character to upper case. * If character is lower case letter in US-ASCII than it's converted to upper - * case analog. If character is NOT lower case letter than it's returned + * case counterpart. If character is NOT lower case letter than it's returned * unmodified. * * @param c character to convert @@ -197,11 +199,12 @@ toasciilower (char c) mhd_static_inline MHD_FN_CONST_ char toasciiupper (char c) { - return isasciilower (c) ? (char) ((~0x20u) & (unsigned char) c) : c; + return (char) (unsigned char) + (((unsigned char) c) & ~((isasciilower (c) ? 1u : 0u) << 5u)); } -#endif /* Disable unused functions. */ +#endif /* mhd_HAVE_STR_TO_UPPER */ #if defined(MHD_FAVOR_SMALL_CODE) /* Used only in mhd_str_to_uvalue_n() */ @@ -1144,6 +1147,24 @@ mhd_str_is_lowercase_bin_n (size_t len, } +#ifdef mhd_HAVE_STR_TO_UPPER +MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ +MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_OUT_SIZE_ (3,1) void +mhd_str_to_uppercase_bin_n (size_t size, + const char *restrict inbuff, + char *restrict outbuff) +{ + size_t i; + + for (i = 0; i < size; ++i) + outbuff[i] = toasciiupper (inbuff[i]); +} + + +#endif /* mhd_HAVE_STR_TO_UPPER */ + + MHD_INTERNAL MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (1) MHD_FN_PAR_IN_ (1) MHD_FN_PAR_IN_ (2) bool diff --git a/src/mhd2/mhd_str.h b/src/mhd2/mhd_str.h @@ -59,6 +59,12 @@ # include "mhd_limits.h" #endif +#ifndef mhd_HAVE_STR_TO_UPPER +# ifdef MHD_SUPPORT_GNUTLS +# define mhd_HAVE_STR_TO_UPPER 1 +# endif +#endif + /* * Block of functions/macros that use US-ASCII charset as required by HTTP * standards. Not affected by current locale settings. @@ -180,6 +186,24 @@ mhd_str_is_lowercase_bin_n (size_t len, const char *restrict str) MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2,1); + +#ifdef mhd_HAVE_STR_TO_UPPER +/** + * Convert sequence of bytes to upper case US-ASCII letters. + * @param size the size of the data in the @a inbuff + * @param inbuff the input data, does not need to be zero-terminated; + * if it is zero-terminated and zero-termination of @a outbuff + * is needed, make sure that @a size includes zero-termination + * @param[out] outbuff the output buffer; should have at least @a size bytes + * available + */ +MHD_INTERNAL void +mhd_str_to_uppercase_bin_n (size_t size, + const char *restrict inbuff, + char *restrict outbuff) +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2,1) MHD_FN_PAR_OUT_SIZE_ (3,1); +#endif /* mhd_HAVE_STR_TO_UPPER */ + /** * Check whether @a str has case-insensitive @a token. * Token could be surrounded by spaces and tabs and delimited by comma.