From 2515ccc0a04d2b73e710e5e6754961dd3d7b304f Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Wed, 15 Jun 2005 06:04:08 +0000 Subject: [PATCH] *more* cleanups to chars.c and related code git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2669 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 4 ++-- src/chars.c | 43 ++++++++++++++++++++++++++++++++++++------- src/proto.h | 2 ++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index e293fd56..9ee0537a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -75,8 +75,8 @@ CVS code - shortcut_init() and do_next_word(). (DLR) - Detect words more accurately by taking punctuation into account, and convert all word-detecting functions to use the - same wrapper function for ease of maintenance. Changes to - is_alnum_mbchar() (renamed is_word_mbchar()); changes to + same wrapper function for ease of maintenance. New functions + is_punct_mbchar() and is_word_mbchar(); changes to do_next_word(), do_prev_word(), is_whole_word(), do_statusbar_next_word(), and do_statusbar_prev_word(). (DLR) - chars.c: diff --git a/src/chars.c b/src/chars.c index 7d1a19f3..209e9754 100644 --- a/src/chars.c +++ b/src/chars.c @@ -62,6 +62,27 @@ bool is_byte(int c) return ((unsigned int)c == (unsigned char)c); } +/* This function is equivalent to isalnum() for multibyte characters. */ +bool is_alnum_mbchar(const char *c) +{ + assert(c != NULL); + +#ifdef NANO_WIDE + if (!ISSET(NO_UTF8)) { + wchar_t wc; + int c_mb_len = mbtowc(&wc, c, MB_CUR_MAX); + + if (c_mb_len <= 0) { + mbtowc(NULL, NULL, 0); + wc = (unsigned char)*c; + } + + return iswalnum(wc); + } else +#endif + return isalnum((unsigned char)*c); +} + /* This function is equivalent to isblank() for multibyte characters. */ bool is_blank_mbchar(const char *c) { @@ -125,10 +146,8 @@ bool is_cntrl_mbchar(const char *c) return is_cntrl_char((unsigned char)*c); } -/* Return TRUE for a multibyte character found in a word (currently only - * an alphanumeric or punctuation character, and the latter only if - * allow_punct is TRUE) and FALSE otherwise. */ -bool is_word_mbchar(const char *c, bool allow_punct) +/* This function is equivalent to ispunct() for multibyte characters. */ +bool is_punct_mbchar(const char *c) { assert(c != NULL); @@ -142,11 +161,21 @@ bool is_word_mbchar(const char *c, bool allow_punct) wc = (unsigned char)*c; } - return iswalnum(wc) || (allow_punct ? iswpunct(wc) : FALSE); + return iswpunct(wc); } else #endif - return isalnum((unsigned char)*c) || (allow_punct ? - ispunct((unsigned char)*c) : FALSE); + return ispunct((unsigned char)*c); +} + +/* Return TRUE for a multibyte character found in a word (currently only + * an alphanumeric or punctuation character, and the latter only if + * allow_punct is TRUE) and FALSE otherwise. */ +bool is_word_mbchar(const char *c, bool allow_punct) +{ + assert(c != NULL); + + return is_alnum_mbchar(c) || (allow_punct ? is_punct_mbchar(c) : + FALSE); } /* c is a control character. It displays as ^@, ^?, or ^[ch], where ch diff --git a/src/proto.h b/src/proto.h index 527fb1b9..59620e0f 100644 --- a/src/proto.h +++ b/src/proto.h @@ -166,12 +166,14 @@ int nisblank(int c); int niswblank(wint_t wc); #endif bool is_byte(int c); +bool is_alnum_mbchar(const char *c); bool is_blank_mbchar(const char *c); bool is_cntrl_char(int c); #ifdef NANO_WIDE bool is_cntrl_wchar(wint_t wc); #endif bool is_cntrl_mbchar(const char *c); +bool is_punct_mbchar(const char *c); bool is_word_mbchar(const char *c, bool allow_punct); char control_rep(char c); #ifdef NANO_WIDE -- 2.39.5