From: Urban Wallasch Date: Mon, 28 Oct 2019 20:34:33 +0000 (+0100) Subject: * str: line breaks, comments X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=63c055e17c7f923c523b65842a28256d0f8008ce;p=oddbits.git * str: line breaks, comments --- diff --git a/README.html b/README.html index c883fd5..8a72c02 100644 --- a/README.html +++ b/README.html @@ -20,7 +20,7 @@ simple IPv4 and IPv6 based TCP and UDP client/server handling href="/?p=oddbits.git;a=tree;f=str;hb=HEAD"> str - -collection of various inline functions to complement string.h +standard C string processing functions to complement string.h diff --git a/str/str.h b/str/str.h index a14ce7c..382a9b1 100644 --- a/str/str.h +++ b/str/str.h @@ -4,7 +4,20 @@ * Copyright (c) 2019, Urban Wallasch * BSD 3-Clause License, see LICENSE file for more details. * - * String comparison and search functions to complement string.h. + * standard C string processing functions to complement string.h + * + * A lot of the functions below are basically clones of non-standard + * extensions found in various C libraries. The code should build and + * work just fine when translated as ISO C99 or above, e.g. with: + * gcc -std=c99 -Wpedantic -Wall -Wextra [...] + * + * The names were chosen in a way that should avoid name clashes with + * existing C library functions. + * + * No claim is made that the particular implementations are the most + * efficient, but the code should perform reasonably well under real + * world conditions when optimized by a decent compiler. + * * * str_icmp, * str_nicmp - compare two strings ignoring case @@ -35,7 +48,7 @@ * str_toupper, * str_tolower - convert case of characters in string * - * str_nlen - determine the length of a fixed-size string + * str_nlen - determine the length of a fixed-size string * * str_ncpy - copy initial part of a string (a better strncpy) * @@ -159,7 +172,8 @@ static inline char *str_istr(const char *haystack, const char *needle) { * not found. If the search pattern is of zero length, the functions * return haystack. */ -static inline void *mem_mem(const void *haystack, size_t h, const void *needle, size_t n) { +static inline void *mem_mem(const void *haystack, size_t h, + const void *needle, size_t n) { if (h >= n) { const char *p = haystack; h -= n; @@ -172,11 +186,13 @@ static inline void *mem_mem(const void *haystack, size_t h, const void *needle, return NULL; } -static inline void *mem_str(const void *haystack, size_t h, const char *needle) { +static inline void *mem_str(const void *haystack, size_t h, + const char *needle) { return mem_mem(haystack, h, needle, needle ? strlen(needle) : 0); } -static inline void *mem_istr(const void *haystack, size_t h, const char *needle) { +static inline void *mem_istr(const void *haystack, size_t h, + const char *needle) { size_t n = needle ? strlen(needle) : 0; if (h >= n) {