From 61b856b73d4cfe0313bb7be5cea399f5134cc897 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Fri, 6 Jul 2007 13:44:13 +0000 Subject: [PATCH] in nstrcasestr(), mbstrcasestr(), revstrstr(), revstrcasestr(), and mbrevstrcasestr(), return char* instead of const char* git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_0_branch/nano@4126 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 1 + src/chars.c | 36 ++++++++++++++++++------------------ src/proto.h | 16 ++++++++-------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8441d8d9..734ef8f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ CVS code - mbrevstrcasestr() - For efficiency, return haystack immediately if needle/rev_start is blank. (DLR) + - Return char* instead of const char*. (DLR) - prompt.c: do_yesno_prompt() - Remove redundant check for NO_HELP's being FALSE. (DLR) diff --git a/src/chars.c b/src/chars.c index 2f3233a6..6c07380e 100644 --- a/src/chars.c +++ b/src/chars.c @@ -602,12 +602,12 @@ int mbstrncasecmp(const char *s1, const char *s2, size_t n) * Boston, MA 02110-1301, USA. */ /* This function is equivalent to strcasestr(). */ -const char *nstrcasestr(const char *haystack, const char *needle) +char *nstrcasestr(const char *haystack, const char *needle) { assert(haystack != NULL && needle != NULL); if (needle == '\0') - return haystack; + return (char *)haystack; for (; *haystack != '\0'; haystack++) { const char *r = haystack, *q = needle; @@ -616,7 +616,7 @@ const char *nstrcasestr(const char *haystack, const char *needle) ; if (*q == '\0') - return haystack; + return (char *)haystack; } return NULL; @@ -624,7 +624,7 @@ const char *nstrcasestr(const char *haystack, const char *needle) #endif /* This function is equivalent to strcasestr() for multibyte strings. */ -const char *mbstrcasestr(const char *haystack, const char *needle) +char *mbstrcasestr(const char *haystack, const char *needle) { #ifdef ENABLE_UTF8 if (use_utf8) { @@ -635,7 +635,7 @@ const char *mbstrcasestr(const char *haystack, const char *needle) assert(haystack != NULL && needle != NULL); if (needle == '\0') - return haystack; + return (char *)haystack; r_mb = charalloc(MB_CUR_MAX); q_mb = charalloc(MB_CUR_MAX); @@ -682,7 +682,7 @@ const char *mbstrcasestr(const char *haystack, const char *needle) free(r_mb); free(q_mb); - return found_needle ? haystack : NULL; + return found_needle ? (char *)haystack : NULL; } else #endif return strcasestr(haystack, needle); @@ -691,13 +691,13 @@ const char *mbstrcasestr(const char *haystack, const char *needle) #if !defined(NANO_TINY) || !defined(DISABLE_TABCOMP) /* This function is equivalent to strstr(), except in that it scans the * string in reverse, starting at rev_start. */ -const char *revstrstr(const char *haystack, const char *needle, const - char *rev_start) +char *revstrstr(const char *haystack, const char *needle, const char + *rev_start) { assert(haystack != NULL && needle != NULL && rev_start != NULL); if (needle == '\0') - return rev_start; + return (char *)rev_start; for (; rev_start >= haystack; rev_start--) { const char *r = rev_start, *q = needle; @@ -706,7 +706,7 @@ const char *revstrstr(const char *haystack, const char *needle, const ; if (*q == '\0') - return rev_start; + return (char *)rev_start; } return NULL; @@ -716,13 +716,13 @@ const char *revstrstr(const char *haystack, const char *needle, const #ifndef NANO_TINY /* This function is equivalent to strcasestr(), except in that it scans * the string in reverse, starting at rev_start. */ -const char *revstrcasestr(const char *haystack, const char *needle, - const char *rev_start) +char *revstrcasestr(const char *haystack, const char *needle, const char + *rev_start) { assert(haystack != NULL && needle != NULL && rev_start != NULL); if (needle == '\0') - return rev_start; + return (char *)rev_start; for (; rev_start >= haystack; rev_start--) { const char *r = rev_start, *q = needle; @@ -731,7 +731,7 @@ const char *revstrcasestr(const char *haystack, const char *needle, ; if (*q == '\0') - return rev_start; + return (char *)rev_start; } return NULL; @@ -740,8 +740,8 @@ const char *revstrcasestr(const char *haystack, const char *needle, /* This function is equivalent to strcasestr() for multibyte strings, * except in that it scans the string in reverse, starting at * rev_start. */ -const char *mbrevstrcasestr(const char *haystack, const char *needle, - const char *rev_start) +char *mbrevstrcasestr(const char *haystack, const char *needle, const + char *rev_start) { #ifdef ENABLE_UTF8 if (use_utf8) { @@ -752,7 +752,7 @@ const char *mbrevstrcasestr(const char *haystack, const char *needle, assert(haystack != NULL && needle != NULL && rev_start != NULL); if (needle == '\0') - return rev_start; + return (char *)rev_start; r_mb = charalloc(MB_CUR_MAX); q_mb = charalloc(MB_CUR_MAX); @@ -803,7 +803,7 @@ const char *mbrevstrcasestr(const char *haystack, const char *needle, free(r_mb); free(q_mb); - return found_needle ? rev_start : NULL; + return found_needle ? (char *)rev_start : NULL; } else #endif return revstrcasestr(haystack, needle, rev_start); diff --git a/src/proto.h b/src/proto.h index 2bd0bfde..3668b2b2 100644 --- a/src/proto.h +++ b/src/proto.h @@ -203,18 +203,18 @@ int nstrncasecmp(const char *s1, const char *s2, size_t n); #endif int mbstrncasecmp(const char *s1, const char *s2, size_t n); #ifndef HAVE_STRCASESTR -const char *nstrcasestr(const char *haystack, const char *needle); +char *nstrcasestr(const char *haystack, const char *needle); #endif -const char *mbstrcasestr(const char *haystack, const char *needle); +char *mbstrcasestr(const char *haystack, const char *needle); #if !defined(NANO_TINY) || !defined(DISABLE_TABCOMP) -const char *revstrstr(const char *haystack, const char *needle, const - char *rev_start); +char *revstrstr(const char *haystack, const char *needle, const char + *rev_start); #endif #ifndef NANO_TINY -const char *revstrcasestr(const char *haystack, const char *needle, - const char *rev_start); -const char *mbrevstrcasestr(const char *haystack, const char *needle, - const char *rev_start); +char *revstrcasestr(const char *haystack, const char *needle, const char + *rev_start); +char *mbrevstrcasestr(const char *haystack, const char *needle, const + char *rev_start); #endif size_t mbstrlen(const char *s); #ifndef HAVE_STRNLEN -- 2.39.5