mirror of
git://git.sv.gnu.org/nano.git
synced 2024-12-24 19:36:52 +03:00
strcasestr() - Replaced by mutt's mutt_stristr function, because the thought of dynamically allocating memory and copying each line in a file to do a search or replace was causing me to lose sleep
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@654 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
parent
64bacd20b5
commit
99afb85752
@ -60,6 +60,11 @@ Cvs code -
|
||||
do_replace()
|
||||
- If we manage to make it in somehow with VIEW_MODE on, abort
|
||||
nicely (fixes BUG #59).
|
||||
- utils.c
|
||||
strcasestr()
|
||||
- Replaced by mutt's mutt_stristr function, because the thought
|
||||
of dynamically allocating memory and copying each line in a file
|
||||
to do a search or replace was causing me to lose sleep.
|
||||
- winio.c:
|
||||
actual_x()
|
||||
- Remove inline from function decl (Albert Chin).
|
||||
|
42
utils.c
42
utils.c
@ -48,37 +48,27 @@ void lowercase(char *src)
|
||||
}
|
||||
|
||||
|
||||
/* I can't believe I have to write this function */
|
||||
/* This is now mutt's version (called mutt_stristr) because it doesn't
|
||||
Use memory allocation to do a simple search (yuck). */
|
||||
|
||||
char *strcasestr(char *haystack, char *needle)
|
||||
{
|
||||
char *localneedle, *localhaystack, *found, *tmp, *tmp2;
|
||||
const char *p, *q;
|
||||
|
||||
/* Make a copy of the search string and search space */
|
||||
localneedle = nmalloc(strlen(needle) + 2);
|
||||
localhaystack = nmalloc(strlen(haystack) + 2);
|
||||
|
||||
strcpy(localneedle, needle);
|
||||
strcpy(localhaystack, haystack);
|
||||
|
||||
/* Make them lowercase */
|
||||
lowercase(localneedle);
|
||||
lowercase(localhaystack);
|
||||
|
||||
/* Look for the lowercased substring in the lowercased search space -
|
||||
return NULL if we didn't find anything */
|
||||
if ((found = strstr(localhaystack, localneedle)) == NULL) {
|
||||
free(localneedle);
|
||||
free(localhaystack);
|
||||
if (!haystack)
|
||||
return NULL;
|
||||
}
|
||||
/* Else return the pointer to the same place in the real search space */
|
||||
tmp2 = haystack;
|
||||
for (tmp = localhaystack; tmp != found; tmp++)
|
||||
tmp2++;
|
||||
if (!needle)
|
||||
return (haystack);
|
||||
|
||||
free(localneedle);
|
||||
free(localhaystack);
|
||||
return tmp2;
|
||||
while (*(p = haystack))
|
||||
{
|
||||
for (q = needle; *p && *q && tolower (*p) == tolower (*q); p++, q++)
|
||||
;
|
||||
if (!*q)
|
||||
return (haystack);
|
||||
haystack++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *strstrwrapper(char *haystack, char *needle)
|
||||
|
Loading…
Reference in New Issue
Block a user