diff options
-rw-r--r-- | src/string/new.c | 217 | ||||
-rw-r--r-- | src/wchar/new.c | 213 |
2 files changed, 430 insertions, 0 deletions
diff --git a/src/string/new.c b/src/string/new.c index 6c035e0..7854e1b 100644 --- a/src/string/new.c +++ b/src/string/new.c @@ -438,3 +438,220 @@ char* memmemcpy(void* whither, const void* whence, const char* restrict str, return r; } +void* (memcasestarts)(const void* string, const void* desired, size_t size) /* slibc: completeness */ +{ + return (memcasecmp)(string, desired, size) ? NULL : string; +} + +char* (strncasestarts)(const char* string, const char* desired, size_t maxlen) /* slibc: completeness */ +{ + size_t n = strnlen(string, maxlen); + size_t m = strnlen(desired, maxlen); + if (n < m) + return NULL; + return (memcasecmp)(string, desired, m) ? NULL : string; +} + +void* (memcaseends)(const void* string, size_t string_size, const void* desired, size_t desired_size) /* slibc: completeness */ +{ + return (memcasecmp)(string + (string_size - desired_size), desired, desired_size) + ? NULL : (string + string_size); +} + +char* (strncaseends)(const char* string, const char* desired, size_t maxlen) /* slibc: completeness */ +{ + size_t n = strnlen(string, maxlen); + size_t m = strnlen(desired, maxlen); + if (n < m) + return NULL; + return (memcasecmp)(string + (n - m), desired, m) ? NULL : (string + n); +} + +void* (memstarts)(const void* string, const void* desired, size_t size) /* slibc */ +{ + return (memcmp)(string, desired, size) ? NULL : string; +} + +char* (strnstarts)(const char* string, const char* desired, size_t maxlen) /* slibc: completeness */ +{ + size_t n = strnlen(string, maxlen); + size_t m = strnlen(desired, maxlen); + if (n < m) + return NULL; + return (memcmp)(string, desired, m) ? NULL : string; +} + +void* (memends)(const void* string, size_t string_size, const void* desired, size_t desired_size) /* slibc: completeness */ +{ + return (memcmp)(string + (string_size - desired_size), desired, desired_size) + ? NULL : (string + string_size); +} + +char* (strnends)(const char* string, const char* desired, size_t maxlen) /* slibc: completeness */ +{ + size_t n = strnlen(string, maxlen); + size_t m = strnlen(desired, maxlen); + if (n < m) + return NULL; + return (memcmp)(string + (n - m), desired, m) ? NULL : (string + n); +} + +int memccasecmp(const void* a, const void* b, size_t size, int stop) /* slibc: completeness */ +{ + const signed char* s1 = a; + const signed char* s2 = b; + int c1, c2; + for (; c1 = (int)*s1++, c2 = (int)*s2++, (c1 != stop) && (c2 != stop) && size; size--) + if (c1 != c2) + { + c1 = isalpha(c1) ? tolower(c1) : c1; + c2 = isalpha(c2) ? tolower(c2) : c2; + if ((c1 -= c2)) + return c1; + } + if (c1 == stop) c1 = 0; + if (c2 == stop) c2 = 0; + return size ? (c1 - c2) : 0; +} + +int memccmp(const void* a, const void* b, size_t size, int stop) /* slibc: completeness */ +{ + const signed char* s1 = a; + const signed char* s2 = b; + int c1, c2; + for (; c1 = (int)*s1++, c2 = (int)*s2++, (c1 != stop) && (c2 != stop) && size; size--) + if (c1 != c2) + return c1 - c2; + if (c1 == stop) c1 = 0; + if (c2 == stop) c2 = 0; + return size ? (c1 - c2) : 0; +} + +int strccasecmp(const char* a, const char* b, int stop) /* slibc: completeness */ +{ + return strcncasecmp(a, b, stop, SIZE_MAX); +} + +int strccmp(const char* a, const char* b, int stop) /* slibc */ +{ + size_t n = strclen(a, stop); + size_t m = strclen(b, stop); + return memcmp(a, b, (n < m ? n : m) + 1); +} + +int strcncasecmp(const char* a, const char* b, int stop, size_t length) /* slibc: completeness */ +{ + size_t n = strcnlen(a, stop, length); + size_t m = strcnlen(b, stop, length); + int r = memcasecmp(a, b, (n < m ? n : m)); + return r ? r : n == m ? 0 : n < m ? -1 : +1; +} + +int strcncmp(const char* a, const char* b, int stop, size_t length) /* slibc: completeness */ +{ + size_t n = strcnlen(a, stop, length); + size_t m = strcnlen(b, stop, length); + int r = memcmp(a, b, (n < m ? n : m)); + return r ? r : n == m ? 0 : n < m ? -1 : +1; +} + +void* (memccasestarts)(const void* string, const void* desired, size_t size, int stop) /* slibc: completeness */ +{ + return (memccasecmp)(string, desired, size, stop) ? NULL : string; +} + +void* (memcstarts)(const void* string, const void* desired, size_t size, int stop) /* slibc: completeness */ +{ + return (memccmp)(string, desired, size, stop) ? NULL : string; +} + +char* (strccasestarts)(const char* string, const char* desired, int stop) /* slibc: completeness */ +{ + size_t n = strclen(string, stop); + size_t m = strclen(desired, stop); + if (n < m) + return NULL; + return (memcasecmp)(string, desired, m) ? NULL : string; +} + +char* (strcstarts)(const char* string, const char* desired, int stop) /* slibc: completeness */ +{ + size_t n = strclen(string, stop); + size_t m = strclen(desired, stop); + if (n < m) + return NULL; + return (memcmp)(string, desired, m) ? NULL : string; +} + +char* (strcncasestarts)(const char* string, const char* desired, int stop, size_t maxlen) /* slibc: completeness */ +{ + size_t n = strcnlen(string, stop, maxlen); + size_t m = strcnlen(desired, stop, maxlen); + if (n < m) + return NULL; + return (memcasecmp)(string, desired, m) ? NULL : string; +} + +char* (strcnstarts)(const char* string, const char* desired, int stop, size_t maxlen) /* slibc: completeness */ +{ + size_t n = strcnlen(string, stop, maxlen); + size_t m = strcnlen(desired, stop, maxlen); + if (n < m) + return NULL; + return (memcmp)(string, desired, m) ? NULL : string; +} + +void* (memccaseends)(const void* string, size_t string_size, const void* desired, size_t desired_size, int stop) /* slibc: completeness */ +{ + void* end = memchr(string, stop, string); + if (end != NULL) + string_size = (size_t)(end - string); + return (memcasecmp)(string + (string_size - desired_size), desired, desired_size) + ? NULL : (string + string_size); +} + +void* (memcends)(const void* string, size_t string_size, const void* desired, size_t desired_size, int stop) /* slibc: completeness */ +{ + void* end = wmemchr(string, stop, string); + if (end != NULL) + string_size = (size_t)(end - string); + return (memcmp)(string + (string_size - desired_size), desired, desired_size) + ? NULL : (string + string_size); +} + +char* (strccaseends)(const char* string, const char* desired, int stop) /* slibc: completeness */ +{ + size_t n = strclen(string, stop); + size_t m = strclen(desired, stop); + if (n < m) + return NULL; + return (memcasecmp)(string + (n - m), desired, m) ? NULL : (string + n); +} + +char* (strcends)(const char* string, const char* desired, int stop) /* slibc: completeness */ +{ + size_t n = strclen(string, stop); + size_t m = strclen(desired, stop); + if (n < m) + return NULL; + return (memcmp)(string + (n - m), desired, m) ? NULL : (string + n); +} + +char* (strcncaseends)(const char* string, const char* desired, int stop, size_t maxlen) /* slibc: completeness */ +{ + size_t n = strcnlen(string, stop, maxlen); + size_t m = strcnlen(desired, stop, maxlen); + if (n < m) + return NULL; + return (memcasecmp)(string + (n - m), desired, m) ? NULL : (string + n); +} + +char* (strcnends)(const char* string, const char* desired, int stop, size_t maxlen) /* slibc: completeness */ +{ + size_t n = strcnlen(string, stop, maxlen); + size_t m = strcnlen(desired, stop, maxlen); + if (n < m) + return NULL; + return (memcmp)(string + (n - m), desired, m) ? NULL : (string + n); +} + diff --git a/src/wchar/new.c b/src/wchar/new.c index f1ee58c..da1d254 100644 --- a/src/wchar/new.c +++ b/src/wchar/new.c @@ -356,3 +356,216 @@ char* wmemmemcpy(wchar_t* whither, const wchar_t* whence, const wchar_t* restric return r; } +wchar_t* (wmemcasestarts)(const wchar_t* string, const wchar_t* desired, size_t size) /* slibc: completeness */ +{ + return (wmemcasecmp)(string, desired, size) ? NULL : string; +} + +wchar_t* (wcsncasestarts)(const wchar_t* string, const wchar_t* desired, size_t maxlen) /* slibc: completeness */ +{ + size_t n = wcsnlen(string, maxlen); + size_t m = wcsnlen(desired, maxlen); + if (n < m) + return NULL; + return (wmemcasecmp)(string, desired, m) ? NULL : string; +} + +wchar_t* (wmemcaseends)(const wchar_t* string, size_t string_size, const wchar_t* desired, size_t desired_size) /* slibc: completeness */ +{ + return (wmemcasecmp)(string + (string_size - desired_size), desired, desired_size) + ? NULL : (string + string_size); +} + +wchar_t* (wcsncaseends)(const wchar_t* string, const wchar_t* desired, size_t maxlen) /* slibc: completeness */ +{ + size_t n = wcsnlen(string, maxlen); + size_t m = wcsnlen(desired, maxlen); + if (n < m) + return NULL; + return (wmemcasecmp)(string + (n - m), desired, m) ? NULL : (string + n); +} + +wchar_t* (wmemstarts)(const wchar_t* string, const wchar_t* desired, size_t size) /* slibc completeness */ +{ + return (wmemcmp)(string, desired, size) ? NULL : string; +} + +wchar_t* (wstrnstarts)(const wchar_t* string, const wchar_t* desired, size_t maxlen) /* slibc: completeness */ +{ + size_t n = wcsnlen(string, maxlen); + size_t m = wcsnlen(desired, maxlen); + if (n < m) + return NULL; + return (wmemcmp)(string, desired, m) ? NULL : string; +} + +wchar_t* (wmemends)(const wchar_t* string, size_t string_size, const wchar_t* desired, size_t desired_size) /* slibc: completeness */ +{ + return (wmemcmp)(string + (string_size - desired_size), desired, desired_size) + ? NULL : (string + string_size); +} + +wchar_t* (wcsnends)(const wchar_t* string, const wchar_t* desired, size_t maxlen) /* slibc: completeness */ +{ + size_t n = wcsnlen(string, maxlen); + size_t m = wcsnlen(desired, maxlen); + if (n < m) + return NULL; + return (wmemcmp)(string + (n - m), desired, m) ? NULL : (string + n); +} + +int wmemccasecmp(const wchar_t* a, const wchar_t* b, size_t size, wchar_t stop) /* slibc: completeness */ +{ + int c1, c2; + for (; c1 = *a++, c2 = *b++, (c1 != stop) && (c2 != stop) && size; size--) + if (c1 != c2) + { + c1 = isalpha(c1) ? tolower(c1) : c1; + c2 = isalpha(c2) ? tolower(c2) : c2; + if ((c1 -= c2)) + return c1; + } + if (c1 == stop) c1 = 0; + if (c2 == stop) c2 = 0; + return size ? (c1 < c2 ? -1 : c1 > c2 ? 1 : 0) : 0; +} + +int wmemccmp(const wchar_t* a, const wchar_t* b, size_t size, wchar_t stop) /* slibc: completeness */ +{ + wchar_t c1, c2; + for (; c1 = *a++, c2 = *b++, (c1 != stop) && (c2 != stop) && size; size--) + if (c1 != c2) + return c1 - c2; + if (c1 == stop) c1 = 0; + if (c2 == stop) c2 = 0; + return size ? (c1 < c2 ? -1 : c1 > c2 ? 1 : 0) : 0; +} + +int wcsccasecmp(const wchar_t* a, const wchar_t* b, wchar_t stop) /* slibc: completeness */ +{ + return wcscncasecmp(a, b, stop, SIZE_MAX); +} + +int wcsccmp(const wchar_t* a, const wchar_t* b, wchar_t stop) /* slibc: completeness */ +{ + size_t n = wcsclen(a, stop); + size_t m = wcsclen(b, stop); + return wmemcmp(a, b, (n < m ? n : m) + 1); +} + +int wcscncasecmp(const wchar_t* a, const wchar_t* b, wchar_t stop, size_t length) /* slibc: completeness */ +{ + size_t n = wcscnlen(a, stop, length); + size_t m = wcscnlen(b, stop, length); + int r = wmemcasecmp(a, b, (n < m ? n : m)); + return r ? r : n == m ? 0 : n < m ? -1 : +1; +} + +int wcscncmp(const wchar_t* a, const wchar_t* b, wchar_t stop, size_t length) /* slibc: completeness */ +{ + size_t n = wcscnlen(a, stop, length); + size_t m = wcscnlen(b, stop, length); + int r = wmemcmp(a, b, (n < m ? n : m)); + return r ? r : n == m ? 0 : n < m ? -1 : +1; +} + +wchar_t* (wmemccasestarts)(const wchar_t* string, const wchar_t* desired, size_t size, wchar_t stop) /* slibc: completeness */ +{ + return (wmemccasecmp)(string, desired, size, stop) ? NULL : string; +} + +wchar_t* (wmemcstarts)(const wchar_t* string, const wchar_t* desired, size_t size, wchar_t stop) /* slibc: completeness */ +{ + return (wmemccmp)(string, desired, size, stop) ? NULL : string; +} + +wchar_t* (wcsccasestarts)(const wchar_t* string, const wchar_t* desired, wchar_t stop) /* slibc: completeness */ +{ + size_t n = wcsclen(string, stop); + size_t m = wcsclen(desired, stop); + if (n < m) + return NULL; + return (wmemcasecmp)(string, desired, m) ? NULL : string; +} + +wchar_t* (wcscstarts)(const wchar_t* string, const wchar_t* desired, wchar_t stop) /* slibc: completeness */ +{ + size_t n = wcsclen(string, stop); + size_t m = wcsclen(desired, stop); + if (n < m) + return NULL; + return (wmemcmp)(string, desired, m) ? NULL : string; +} + +wchar_t* (wcscncasestarts)(const wchar_t* string, const wchar_t* desired, wchar_t stop, size_t maxlen) /* slibc: completeness */ +{ + size_t n = wcscnlen(string, stop, maxlen); + size_t m = wcscnlen(desired, stop, maxlen); + if (n < m) + return NULL; + return (wmemcasecmp)(string, desired, m) ? NULL : string; +} + +wchar_t* (wcscnstarts)(const wchar_t* string, const wchar_t* desired, wchar_t stop, size_t maxlen) /* slibc: completeness */ +{ + size_t n = wcscnlen(string, stop, maxlen); + size_t m = wcscnlen(desired, stop, maxlen); + if (n < m) + return NULL; + return (wmemcmp)(string, desired, m) ? NULL : string; +} + +wchar_t* (wmemccaseends)(const wchar_t* string, size_t string_size, const wchar_t* desired, size_t desired_size, wchar_t stop) /* slibc: completeness */ +{ + wchar_t* end = wmemchr(string, stop, string); + if (end != NULL) + string_size = (size_t)(end - string); + return (wmemcasecmp)(string + (string_size - desired_size), desired, desired_size) + ? NULL : (string + string_size); +} + +wchar_t* (wmemcends)(const wchar_t* string, size_t string_size, const wchar_t* desired, size_t desired_size, wchar_t stop) /* slibc: completeness */ +{ + wchar_t* end = wmemchr(string, stop, string); + if (end != NULL) + string_size = (size_t)(end - string); + return (wmemcmp)(string + (string_size - desired_size), desired, desired_size) + ? NULL : (string + string_size); +} + +wchar_t* (wcsccaseends)(const wchar_t* string, const wchar_t* desired, wchar_t stop) /* slibc: completeness */ +{ + size_t n = wcsclen(string, stop); + size_t m = wcsclen(desired, stop); + if (n < m) + return NULL; + return (wmemcasecmp)(string + (n - m), desired, m) ? NULL : (string + n); +} + +wchar_t* (wcscends)(const wchar_t* string, const wchar_t* desired, wchar_t stop) /* slibc: completeness */ +{ + size_t n = wcsclen(string, stop); + size_t m = wcsclen(desired, stop); + if (n < m) + return NULL; + return (wmemcmp)(string + (n - m), desired, m) ? NULL : (string + n); +} + +wchar_t* (wcscncaseends)(const wchar_t* string, const wchar_t* desired, wchar_t stop, size_t maxlen) /* slibc: completeness */ +{ + size_t n = wcscnlen(string, stop, maxlen); + size_t m = wcscnlen(desired, stop, maxlen); + if (n < m) + return NULL; + return (wmemcasecmp)(string + (n - m), desired, m) ? NULL : (string + n); +} + +wchar_t* (wcscnends)(const wchar_t* string, const wchar_t* desired, wchar_t stop, size_t maxlen) /* slibc: completeness */ +{ + size_t n = wcscnlen(string, stop, maxlen); + size_t m = wcscnlen(desired, stop, maxlen); + if (n < m) + return NULL; + return (wmemcmp)(string + (n - m), desired, m) ? NULL : (string + n); +} + |