simplify the word detection code
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2641 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
67287088dc
commit
f26d386191
|
@ -67,8 +67,8 @@ CVS code -
|
||||||
shortcut_init() and do_next_word(). (DLR)
|
shortcut_init() and do_next_word(). (DLR)
|
||||||
- Detect words more accurately by taking punctuation into
|
- Detect words more accurately by taking punctuation into
|
||||||
account, and convert all word-detecting functions to use the
|
account, and convert all word-detecting functions to use the
|
||||||
same wrapper function for ease of maintenance. New functions
|
same wrapper function for ease of maintenance. Changes to
|
||||||
is_punct_mbchar() and is_word_mbchar(); changes to
|
is_alnum_mbchar() (renamed is_word_mbchar()); changes to
|
||||||
do_next_word(), do_prev_word(), is_whole_word(),
|
do_next_word(), do_prev_word(), is_whole_word(),
|
||||||
do_statusbar_next_word(), and do_statusbar_prev_word(). (DLR)
|
do_statusbar_next_word(), and do_statusbar_prev_word(). (DLR)
|
||||||
- chars.c:
|
- chars.c:
|
||||||
|
|
38
src/chars.c
38
src/chars.c
|
@ -46,27 +46,6 @@ bool is_byte(int c)
|
||||||
return ((unsigned int)c == (unsigned char)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);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef HAVE_ISBLANK
|
#ifndef HAVE_ISBLANK
|
||||||
/* This function is equivalent to isblank(). */
|
/* This function is equivalent to isblank(). */
|
||||||
bool nisblank(int c)
|
bool nisblank(int c)
|
||||||
|
@ -146,8 +125,9 @@ bool is_cntrl_mbchar(const char *c)
|
||||||
return is_cntrl_char((unsigned char)*c);
|
return is_cntrl_char((unsigned char)*c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is equivalent to ispunct() for multibyte characters. */
|
/* Return TRUE for a multibyte character found in a word (currently only
|
||||||
bool is_punct_mbchar(const char *c)
|
* an alphanumeric or punctuation character) and FALSE otherwise. */
|
||||||
|
bool is_word_mbchar(const char *c)
|
||||||
{
|
{
|
||||||
assert(c != NULL);
|
assert(c != NULL);
|
||||||
|
|
||||||
|
@ -161,18 +141,10 @@ bool is_punct_mbchar(const char *c)
|
||||||
wc = (unsigned char)*c;
|
wc = (unsigned char)*c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return iswpunct(wc);
|
return iswalnum(wc) || iswpunct(wc);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
return ispunct((unsigned char)*c);
|
return isalnum((unsigned char)*c) || ispunct((unsigned char)*c);
|
||||||
}
|
|
||||||
|
|
||||||
/* This function returns TRUE for a multibyte character found in a word
|
|
||||||
* (currently only an alphanumeric or punctuation character) and FALSE
|
|
||||||
* otherwise. */
|
|
||||||
bool is_word_mbchar(const char *c)
|
|
||||||
{
|
|
||||||
return is_alnum_mbchar(c) || is_punct_mbchar(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* c is a control character. It displays as ^@, ^?, or ^[ch], where ch
|
/* c is a control character. It displays as ^@, ^?, or ^[ch], where ch
|
||||||
|
|
|
@ -160,7 +160,6 @@ extern char *homedir;
|
||||||
|
|
||||||
/* Public functions in chars.c. */
|
/* Public functions in chars.c. */
|
||||||
bool is_byte(int c);
|
bool is_byte(int c);
|
||||||
bool is_alnum_mbchar(const char *c);
|
|
||||||
#ifndef HAVE_ISBLANK
|
#ifndef HAVE_ISBLANK
|
||||||
bool nisblank(int c);
|
bool nisblank(int c);
|
||||||
#endif
|
#endif
|
||||||
|
@ -173,7 +172,6 @@ bool is_cntrl_char(int c);
|
||||||
bool is_cntrl_wchar(wint_t wc);
|
bool is_cntrl_wchar(wint_t wc);
|
||||||
#endif
|
#endif
|
||||||
bool is_cntrl_mbchar(const char *c);
|
bool is_cntrl_mbchar(const char *c);
|
||||||
bool is_punct_mbchar(const char *c);
|
|
||||||
bool is_word_mbchar(const char *c);
|
bool is_word_mbchar(const char *c);
|
||||||
char control_rep(char c);
|
char control_rep(char c);
|
||||||
#ifdef NANO_WIDE
|
#ifdef NANO_WIDE
|
||||||
|
|
Loading…
Reference in New Issue