* 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
* 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)
*
* 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;
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) {