reorganization: move revstrstr() back to chars.c, and move is_byte()

there too, since they both deal with strings and hence characters


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2286 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-01-18 17:00:00 +00:00
parent 2bd22761ac
commit 21954765ca
4 changed files with 38 additions and 33 deletions

View File

@ -98,11 +98,12 @@ CVS code -
is_blank_wchar(), is_cntrl_mbchar(), is_cntrl_wchar(),
control_mbrep(), control_wrep(), mbwidth(), mb_cur_max(),
make_mbchar(), mbstrnlen(), mbstrcasecmp(), and
mbstrncasecmp(); changes to is_blank_char() (moved to
chars.c), is_cntrl_char() (moved to chars.c), nstricmp()
(renamed nstrcasecmp() and moved to chars.c), nstrnicmp()
(renamed nstrncasecmp() and moved to chars.c), nstristr()
(renamed nstrcasestr() and moved to chars.c), revstristr()
mbstrncasecmp(); changes to is_byte() (moved to chars.c),
is_blank_char() (moved to chars.c), is_cntrl_char() (moved to
chars.c), nstricmp() (renamed nstrcasecmp() and moved to
chars.c), nstrnicmp() (renamed nstrncasecmp() and moved to
chars.c), nstristr() (renamed nstrcasestr() and moved to
chars.c), revstrstr() (moved to chars.c), revstristr()
(renamed revstrcasestr() and moved to chars.c), nstrnlen()
(moved to chars.c), parse_char() (renamed parse_mbchar() and
moved to chars.c), move_left() (renamed move_mbleft() and

View File

@ -38,6 +38,13 @@
#include <wctype.h>
#endif
/* Return TRUE if the value of c is in byte range, and FALSE
* otherwise. */
bool is_byte(unsigned int c)
{
return (c == (unsigned char)c);
}
/* This function is equivalent to isalnum(). */
bool is_alnum_char(unsigned int c)
{
@ -596,6 +603,28 @@ const char *nstrcasestr(const char *haystack, const char *needle)
#endif
#ifndef NANO_SMALL
/* This function is equivalent to strstr(), except in that it scans the
* string in reverse. */
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;
}
/* This function is equivalent to strcasestr(), except in that it scans
* the string in reverse. */
const char *revstrcasestr(const char *haystack, const char *needle,
const char *rev_start)
{

View File

@ -151,6 +151,7 @@ extern char *homedir;
/* Functions we want available. */
/* Public functions in chars.c. */
bool is_byte(unsigned int c);
bool is_alnum_char(unsigned int c);
bool is_alnum_mbchar(const char *c);
#ifdef NANO_WIDE
@ -525,7 +526,6 @@ int regexec_safe(const regex_t *preg, const char *string, size_t nmatch,
int regexp_bol_or_eol(const regex_t *preg, const char *string);
#endif
int num_of_digits(int n);
bool is_byte(unsigned int c);
bool parse_num(const char *str, ssize_t *val);
void align(char **strp);
void null_at(char **data, size_t index);

View File

@ -67,11 +67,6 @@ int num_of_digits(int n)
return i;
}
bool is_byte(unsigned int c)
{
return (c == (unsigned char)c);
}
/* Read a ssize_t from str, and store it in *val (if val is not NULL).
* On error, we return FALSE and don't change *val. Otherwise, we
* return TRUE. */
@ -131,26 +126,7 @@ void sunder(char *str)
}
}
#ifndef NANO_SMALL
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;
}
#ifdef ENABLE_NANORC
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
#ifndef HAVE_GETLINE
/* This function is equivalent to getline(). It was adapted from
* GNU mailutils' getline() function. */
@ -208,8 +184,7 @@ ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream)
return (c == EOF && (indx - 1) == 0) ? -1 : indx - 1;
}
#endif
#endif /* ENABLE_NANORC */
#endif /* !NANO_SMALL */
#endif /* !NANO_SMALL && ENABLE_NANORC */
/* If we are searching backwards, we will find the last match that
* starts no later than start. Otherwise we find the first match