From 66444c37b3fe47c355611b00f4ea1a2a181deae8 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Thu, 21 Jul 2005 18:05:27 +0000 Subject: [PATCH] more function reordering git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2908 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- src/chars.c | 92 ++++++++++++++++++++++++++--------------------------- src/proto.h | 2 +- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/chars.c b/src/chars.c index 506ad1d4..ea80c2fa 100644 --- a/src/chars.c +++ b/src/chars.c @@ -753,6 +753,52 @@ size_t mbstrnlen(const char *s, size_t maxlen) } #ifndef DISABLE_JUSTIFY +/* This function is equivalent to strchr() for multibyte strings. */ +char *mbstrchr(const char *s, char *c) +{ + assert(s != NULL && c != NULL); + +#ifdef ENABLE_UTF8 + if (ISSET(USE_UTF8)) { + bool bad_c_mb = FALSE, bad_s_mb = FALSE; + char *s_mb = charalloc(MB_CUR_MAX); + const char *q = s; + wchar_t ws, wc; + int c_mb_len = mbtowc(&wc, c, MB_CUR_MAX); + + if (c_mb_len <= 0) { + mbtowc(NULL, NULL, 0); + wc = (unsigned char)*c; + bad_c_mb = TRUE; + } + + while (*s != '\0') { + int s_mb_len = parse_mbchar(s, s_mb, NULL, NULL); + + if (mbtowc(&ws, s_mb, s_mb_len) <= 0) { + mbtowc(NULL, NULL, 0); + ws = (unsigned char)*s; + bad_s_mb = TRUE; + } + + if (bad_s_mb == bad_c_mb && ws == wc) + break; + + s += s_mb_len; + q += s_mb_len; + } + + free(s_mb); + + if (ws != wc) + q = NULL; + + return (char *)q; + } else +#endif + return strchr(s, *c); +} + #ifdef ENABLE_NANORC /* Return TRUE if the string s contains one or more blank characters, * and FALSE otherwise. */ @@ -800,52 +846,6 @@ bool has_blank_mbchars(const char *s) return has_blank_chars(s); } #endif /* ENABLE_NANORC */ - -/* This function is equivalent to strchr() for multibyte strings. */ -char *mbstrchr(const char *s, char *c) -{ - assert(s != NULL && c != NULL); - -#ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { - bool bad_c_mb = FALSE, bad_s_mb = FALSE; - char *s_mb = charalloc(MB_CUR_MAX); - const char *q = s; - wchar_t ws, wc; - int c_mb_len = mbtowc(&wc, c, MB_CUR_MAX); - - if (c_mb_len <= 0) { - mbtowc(NULL, NULL, 0); - wc = (unsigned char)*c; - bad_c_mb = TRUE; - } - - while (*s != '\0') { - int s_mb_len = parse_mbchar(s, s_mb, NULL, NULL); - - if (mbtowc(&ws, s_mb, s_mb_len) <= 0) { - mbtowc(NULL, NULL, 0); - ws = (unsigned char)*s; - bad_s_mb = TRUE; - } - - if (bad_s_mb == bad_c_mb && ws == wc) - break; - - s += s_mb_len; - q += s_mb_len; - } - - free(s_mb); - - if (ws != wc) - q = NULL; - - return (char *)q; - } else -#endif - return strchr(s, *c); -} #endif /* !DISABLE_JUSTIFY */ #ifdef ENABLE_NANORC diff --git a/src/proto.h b/src/proto.h index 1adbdfde..ad442189 100644 --- a/src/proto.h +++ b/src/proto.h @@ -197,11 +197,11 @@ size_t nstrnlen(const char *s, size_t maxlen); #endif size_t mbstrnlen(const char *s, size_t maxlen); #ifndef DISABLE_JUSTIFY +char *mbstrchr(const char *s, char *c); #ifdef ENABLE_NANORC bool has_blank_chars(const char *s); bool has_blank_mbchars(const char *s); #endif -char *mbstrchr(const char *s, char *c); #endif #ifdef ENABLE_NANORC bool is_valid_mbstring(const char *s);