From e2d52adc78d14ba3d2c6a6017798c704a2ffb4c5 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 1 Sep 2015 06:03:04 +0200 Subject: add strstr functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- include/string.h | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/wchar.h | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 259 insertions(+) (limited to 'include') diff --git a/include/string.h b/include/string.h index f1cc0c1..8034973 100644 --- a/include/string.h +++ b/include/string.h @@ -848,6 +848,131 @@ char* strrchr(const char*, int) /* TODO Add case insensitive character searching functions. */ +/** + * Finds the first occurrence of a substring. + * This search is case sensitive. + * + * @param haystack The string to search. + * @param needle The sought after substring. + * @return Pointer to the first occurrence of the + * substring, `NULL` if not found. + */ +char* strstr(const char*, const char*) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull))); + +/** + * Finds the first occurrence of a substring. + * This search is case insensitive. + * + * @param haystack The string to search. + * @param needle The sought after substring. + * @return Pointer to the first occurrence of the + * substring, `NULL` if not found. + */ +char* strcasestr(const char*, const char*) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull))); + +#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE) +/** + * Finds the first occurrence of a substring. + * This search is case sensitive. + * + * This is a slibc extension added for because it was useful + * in implementing slibc itself. + * + * @param haystack The string to search. + * @param needle The sought after substring. + * @param maxlen The maximum number of character to search. + * @return Pointer to the first occurrence of the + * substring, `NULL` if not found. + */ +char* strnstr(const char*, const char*, size_t) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull))); + +/** + * Finds the first occurrence of a substring. + * This search is case insensitive. + * + * This is a slibc extension added for completeness. + * + * @param haystack The string to search. + * @param needle The sought after substring. + * @param maxlen The maximum number of character to search. + * @return Pointer to the first occurrence of the + * substring, `NULL` if not found. + */ +char* strncasestr(const char*, const char*, size_t) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull))); + +/** + * Finds the first occurrence of a substring. + * This search is case sensitive. + * It must already be known that such a substring exists. + * + * This is a slibc extension. + * + * @param haystack The string to search. + * @param needle The sought after substring. + * @return Pointer to the first occurrence of the substring. + */ +char* rawstrstr(const char*, const char*) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull, returns_nonnull))); + +/** + * Finds the first occurrence of a substring. + * This search is case insensitive. + * It must already be known that such a substring exists. + * + * This is a slibc extension. + * + * @param haystack The string to search. + * @param needle The sought after substring. + * @return Pointer to the first occurrence of the substring. + */ +char* rawstrcasestr(const char*, const char*) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull, returns_nonnull))); + +/** + * Finds the first occurrence of a substring + * This search is case insensitive. + * + * This is a slibc extension added because it was useful + * in implementing slibc itself. + * + * @param haystack The string to search. + * @param haystack_length The number of character to search. + * @param needle The sought after substring. + * @param needle_length The length of `needle`. + * @return Pointer to the first occurrence of + * the substring, `NULL` if not found. + */ +void* memcasemem(const void*, size_t, const void*, size_t) + __GCC_ONLY(__attribute__((warn_unused_result))); +#endif + +#if (defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)) && !defined(__PORTABLE) +/** + * Finds the first occurrence of a substring + * This search is case sensitive. + * + * This is a GNU-compliant slibc extension. It was useful + * in implementing slibc itself. + * + * @param haystack The string to search. + * @param haystack_length The number of character to search. + * @param needle The sought after substring. + * @param needle_length The length of `needle`. + * @return Pointer to the first occurrence of + * the substring, `NULL` if not found. + */ +void* memmem(const void*, size_t, const void*, size_t) + __GCC_ONLY(__attribute__((warn_unused_result))); +#endif + + +/* TODO Add case right-to-left substring searching functions. */ + + #endif diff --git a/include/wchar.h b/include/wchar.h index 66c4127..16644c8 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -804,6 +804,140 @@ wchar_t* wcsrchr(const wchar_t*, wchar_t) /* TODO Add case insensitive character searching functions. */ +/** + * This function is identical to `wcsstr`. + */ +wchar_t* wcswcs(const wchar_t*, const wchar_t*) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull))) + __deprecated("Use 'wcsstr' instead."); + +/** + * Finds the first occurrence of a substring. + * This search is case sensitive. + * + * @param haystack The string to search. + * @param needle The sought after substring. + * @return Pointer to the first occurrence of the + * substring, `NULL` if not found. + */ +wchar_t* wcsstr(const wchar_t*, const wchar_t*) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull))); + +#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE) +/** + * Finds the first occurrence of a substring. + * This search is case insensitive. + * + * This is a slibc extension. + * + * @param haystack The string to search. + * @param needle The sought after substring. + * @return Pointer to the first occurrence of the + * substring, `NULL` if not found. + */ +wchar_t* wcscasestr(const wchar_t*, const wchar_t*) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull))); + +/** + * Finds the first occurrence of a substring. + * This search is case sensitive. + * + * This is a slibc extension added for because it was useful + * in implementing slibc itself. + * + * @param haystack The string to search. + * @param needle The sought after substring. + * @param maxlen The maximum number of character to search. + * @return Pointer to the first occurrence of the + * substring, `NULL` if not found. + */ +wchar_t* wcsnstr(const wchar_t*, const wchar_t*, size_t) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull))); + +/** + * Finds the first occurrence of a substring. + * This search is case insensitive. + * + * This is a slibc extension added for completeness. + * + * @param haystack The string to search. + * @param needle The sought after substring. + * @param maxlen The maximum number of character to search. + * @return Pointer to the first occurrence of the + * substring, `NULL` if not found. + */ +wchar_t* wcsncasestr(const wchar_t*, const wchar_t*, size_t) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull))); + +/** + * Finds the first occurrence of a substring. + * This search is case sensitive. + * It must already be known that such a substring exists. + * + * This is a slibc extension. + * + * @param haystack The string to search. + * @param needle The sought after substring. + * @return Pointer to the first occurrence of the substring. + */ +wchar_t* rawwcsstr(const wchar_t*, const wchar_t*) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull, returns_nonnull))); + +/** + * Finds the first occurrence of a substring. + * This search is case insensitive. + * It must already be known that such a substring exists. + * + * This is a slibc extension. + * + * @param haystack The string to search. + * @param needle The sought after substring. + * @return Pointer to the first occurrence of the substring. + */ +wchar_t* rawwcscasestr(const wchar_t*, const wchar_t*) + __GCC_ONLY(__attribute__((warn_unused_result, nonnull, returns_nonnull))); + +/** + * Finds the first occurrence of a substring + * This search is case insensitive. + * + * This is a slibc extension added because it was useful + * in implementing slibc itself. + * + * @param haystack The string to search. + * @param haystack_length The number of character to search. + * @param needle The sought after substring. + * @param needle_length The length of `needle`. + * @return Pointer to the first occurrence of + * the substring, `NULL` if not found. + */ +wchar_t* wmemcasemem(const wchar_t*, size_t, const wchar_t*, size_t); +#endif + +#if (defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)) && !defined(__PORTABLE) +/** + * Finds the first occurrence of a substring + * This search is case sensitive. + * + * This is a slibc extension added for completeness, + * and because it was it was useful in implementing + * slibc itself. + * + * @param haystack The string to search. + * @param haystack_length The number of character to search. + * @param needle The sought after substring. + * @param needle_length The length of `needle`. + * @return Pointer to the first occurrence of + * the substring, `NULL` if not found. + */ +wchar_t* wmemmem(const wchar_t*, size_t, const wchar_t*, size_t) + __GCC_ONLY(__attribute__((warn_unused_result))); +#endif + + +/* TODO Add case right-to-left substring searching functions. */ + + #endif #endif -- cgit v1.2.3-70-g09d2