* src/lib/evil_string.c:
	* src/lib/evil_string.h:
	Add strcasestr() API.



SVN revision: 70350
This commit is contained in:
Vincent Torri 2012-04-20 07:51:58 +00:00
parent c8412af437
commit f9f6d76e9a
4 changed files with 60 additions and 0 deletions

View File

@ -1,3 +1,10 @@
2012-04-20 Vincent Torri <doursse at users dot sf dot net>
* NEWS:
* src/lib/evil_string.c:
* src/lib/evil_string.h:
Add strcasestr() API.
2012-04-12 Vincent Torri <doursse at users dot sf dot net>
* NEWS:

View File

@ -5,6 +5,7 @@ Evil NEWS - User visible changes.
** Add evil_path_is_absolute() API
** Add POSIX printf() family functions
** Add S_ISLNK macro
** Add strcasestr() API
** Do not declare and define localtime_r() if it's already defined
* Evil 1.0:

View File

@ -92,3 +92,37 @@ int strcasecmp(const char *s1, const char *s2)
}
#endif /* _MSC_VER */
char *strcasestr(const char *haystack, const char *needle)
{
size_t length_needle;
size_t length_haystack;
size_t i;
if (!haystack || !needle)
return NULL;
length_needle = strlen(needle);
length_haystack = strlen(haystack) - length_needle + 1;
for (i = 0; i < length_haystack; i++)
{
size_t j;
for (j = 0; j < length_needle; j++)
{
unsigned char c1;
unsigned char c2;
c1 = haystack[i+j];
c2 = needle[j];
if (toupper(c1) != toupper(c2))
goto next;
}
return (char *) haystack + i;
next:
;
}
return NULL;
}

View File

@ -125,6 +125,24 @@ EAPI int strcasecmp(const char *s1, const char *s2);
#endif /* _MSC_VER */
/**
* @brief Locatea substring into a string, ignoring case.
*
* @param haystack The string to search in.
* @param needle The substring to find.
* @return
*
* This function locates the string @p needle into the string @p haystack,
* ignoring the case of the characters. It returns apointer to the
* beginning of the substring, or NULL if the substring is not found.
* If @p haystack or @p needle are @c NULL, this function returns @c NULL.
*
* Conformity: Non applicable.
*
* Supported OS: Windows XP, Windows CE
*/
EAPI char *strcasestr(const char *haystack, const char *needle);
/**
* @}