From 116c828c50e7e4485e4d2e8e0e0ce2be7d6d3183 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Fri, 14 Jan 2005 03:22:54 +0000 Subject: [PATCH] add asserts, plus a few more cosmetic fixes git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2257 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 2 ++ src/utils.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 33f4e35c..3c8217ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -167,6 +167,8 @@ CVS code - is_blank_char() - Rewrite to use ctype functions instead of checking directly for spaces and tabs. (DLR) + revstrstr(), revstristr() + - Add asserts. (DLR) - winio.c: titlebar() - Rename some variables for consistency, make space an int diff --git a/src/utils.c b/src/utils.c index 36e4a2e1..f471ef5f 100644 --- a/src/utils.c +++ b/src/utils.c @@ -209,8 +209,7 @@ const char *nstristr(const char *haystack, const char *needle) assert(haystack != NULL && needle != NULL); for (; *haystack != '\0'; haystack++) { - const char *p = haystack; - const char *q = needle; + const char *p = haystack, *q = needle; for (; tolower(*p) == tolower(*q) && *q != '\0'; p++, q++) ; @@ -228,28 +227,36 @@ const char *nstristr(const char *haystack, const char *needle) const char *revstrstr(const char *haystack, const char *needle, const char *rev_start) { + assert(haystack != NULL && needle != NULL && rev_start != NULL); + for (; rev_start >= haystack; rev_start--) { const char *r, *q; for (r = rev_start, q = needle; *q == *r && *q != '\0'; r++, q++) ; + if (*q == '\0') return rev_start; } + return NULL; } const char *revstristr(const char *haystack, const char *needle, const char *rev_start) { + assert(haystack != NULL && needle != NULL && rev_start != NULL); + for (; rev_start >= haystack; rev_start--) { const char *r = rev_start, *q = needle; for (; tolower(*q) == tolower(*r) && *q != '\0'; r++, q++) ; + if (*q == '\0') return rev_start; } + return NULL; } #endif /* !NANO_SMALL */