Commit 345260c6 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

add multibyte version of revstrcasestr()

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2296 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 80 additions and 16 deletions
+80 -16
...@@ -98,21 +98,21 @@ CVS code - ...@@ -98,21 +98,21 @@ CVS code -
is_blank_wchar(), is_cntrl_mbchar(), is_cntrl_wchar(), is_blank_wchar(), is_cntrl_mbchar(), is_cntrl_wchar(),
control_mbrep(), control_wrep(), mbwidth(), mb_cur_max(), control_mbrep(), control_wrep(), mbwidth(), mb_cur_max(),
make_mbchar(), mbstrnlen(), mbstrcasecmp(), mbstrncasecmp(), make_mbchar(), mbstrnlen(), mbstrcasecmp(), mbstrncasecmp(),
and mbstrcasestr(); changes to is_byte() (moved to chars.c), mbstrcasestr(), and mbrevstrcasestr(); changes to is_byte()
is_blank_char() (moved to chars.c), is_cntrl_char() (moved to (moved to chars.c), is_blank_char() (moved to chars.c),
chars.c), nstricmp() (renamed nstrcasecmp() and moved to is_cntrl_char() (moved to chars.c), nstricmp() (renamed
chars.c), nstrnicmp() (renamed nstrncasecmp() and moved to nstrcasecmp() and moved to chars.c), nstrnicmp() (renamed
chars.c), nstristr() (renamed nstrcasestr() and moved to nstrncasecmp() and moved to chars.c), nstristr() (renamed
chars.c), revstrstr() (moved to chars.c), revstristr() nstrcasestr() and moved to chars.c), revstrstr() (moved to
(renamed revstrcasestr() and moved to chars.c), nstrnlen() chars.c), revstristr() (renamed revstrcasestr() and moved to
(moved to chars.c), parse_char() (renamed parse_mbchar() and chars.c), nstrnlen() (moved to chars.c), parse_char()
moved to chars.c), move_left() (renamed move_mbleft() and (renamed parse_mbchar() and moved to chars.c), move_left()
moved to chars.c), move_right() (renamed move_mbright() and (renamed move_mbleft() and moved to chars.c), move_right()
moved to chars.c), do_home(), do_verbatim_input(), (renamed move_mbright() and moved to chars.c), do_home(),
do_delete(), do_tab(), do_next_word(), do_prev_word(), do_verbatim_input(), do_delete(), do_tab(), do_next_word(),
do_input(), do_output(), strstrwrapper(), get_buffer(), do_prev_word(), do_input(), do_output(), strstrwrapper(),
unget_input(), unget_kbinput(), get_input(), parse_kbinput(), get_buffer(), unget_input(), unget_kbinput(), get_input(),
unparse_kbinput(), parse_verbatim_kbinput(), parse_kbinput(), unparse_kbinput(), parse_verbatim_kbinput(),
do_statusbar_input(), do_statusbar_home(), do_statusbar_input(), do_statusbar_home(),
do_statusbar_verbatim_kbinput(), do_statusbar_output(), and do_statusbar_verbatim_kbinput(), do_statusbar_output(), and
display_string(); removal of buffer_to_keys() and display_string(); removal of buffer_to_keys() and
......
...@@ -692,6 +692,68 @@ const char *revstrcasestr(const char *haystack, const char *needle, ...@@ -692,6 +692,68 @@ const char *revstrcasestr(const char *haystack, const char *needle,
return NULL; return NULL;
} }
/* 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)
{
#ifdef NANO_WIDE
if (!ISSET(NO_UTF8)) {
char *r_mb = charalloc(MB_CUR_MAX);
char *q_mb = charalloc(MB_CUR_MAX);
wchar_t wr, wq;
bool begin_line = FALSE, found_needle = FALSE;
assert(haystack != NULL && needle != NULL && rev_start != NULL);
while (!begin_line) {
const char *r = rev_start, *q = needle;
int r_mb_len, q_mb_len;
while (*q != '\0') {
r_mb_len = parse_mbchar(r, r_mb, NULL, NULL);
if (mbtowc(&wr, r_mb, r_mb_len) <= 0) {
mbtowc(NULL, NULL, 0);
wr = (unsigned char)*r;
}
q_mb_len = parse_mbchar(q, q_mb, NULL, NULL);
if (mbtowc(&wq, q_mb, q_mb_len) <= 0) {
mbtowc(NULL, NULL, 0);
wq = (unsigned char)*q;
}
if (towlower(wr) != towlower(wq))
break;
r += r_mb_len;
q += q_mb_len;
}
if (*q == '\0') {
found_needle = TRUE;
break;
}
if (rev_start == haystack)
begin_line = TRUE;
else
rev_start = haystack + move_mbleft(haystack, rev_start -
haystack);
}
free(r_mb);
free(q_mb);
return found_needle ? rev_start : NULL;
} else
#endif
return revstrcasestr(haystack, needle, rev_start);
}
#endif #endif
#ifndef HAVE_STRNLEN #ifndef HAVE_STRNLEN
......
...@@ -199,6 +199,8 @@ const char *revstrstr(const char *haystack, const char *needle, const ...@@ -199,6 +199,8 @@ const char *revstrstr(const char *haystack, const char *needle, const
char *rev_start); char *rev_start);
const char *revstrcasestr(const char *haystack, const char *needle, const char *revstrcasestr(const char *haystack, const char *needle,
const char *rev_start); const char *rev_start);
const char *mbrevstrcasestr(const char *haystack, const char *needle,
const char *rev_start);
#endif #endif
#ifndef HAVE_STRNLEN #ifndef HAVE_STRNLEN
size_t nstrnlen(const char *s, size_t maxlen); size_t nstrnlen(const char *s, size_t maxlen);
......
...@@ -243,7 +243,7 @@ const char *strstrwrapper(const char *haystack, const char *needle, ...@@ -243,7 +243,7 @@ const char *strstrwrapper(const char *haystack, const char *needle,
#endif /* !DISABLE_SPELLER || !NANO_SMALL */ #endif /* !DISABLE_SPELLER || !NANO_SMALL */
#ifndef NANO_SMALL #ifndef NANO_SMALL
else if (ISSET(REVERSE_SEARCH)) else if (ISSET(REVERSE_SEARCH))
return revstrcasestr(haystack, needle, start); return mbrevstrcasestr(haystack, needle, start);
#endif #endif
return mbstrcasestr(start, needle); return mbstrcasestr(start, needle);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment