From: David Lawrence Ramsey Date: Fri, 14 Jan 2005 21:50:32 +0000 (+0000) Subject: rename move_left() and move_right() to move_mbleft() and move_mbright(), X-Git-Tag: v1.3.6~132 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=d24fbb760dc87d4dbe915a7055e949c3698b4f16;p=nano.git rename move_left() and move_right() to move_mbleft() and move_mbright(), and move them to chars.c git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2270 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 75acea22..f141a531 100644 --- a/ChangeLog +++ b/ChangeLog @@ -100,7 +100,9 @@ CVS code - mb_cur_max(), and make_mbchar(); changes to is_blank_char() (moved to chars.c), is_cntrl_char() (moved to chars.c), nstrnlen() (moved to chars.c), parse_char() (renamed - parse_mbchar() and moved to chars.c), do_home(), + parse_mbchar() and moved to chars.c), move_left() (renamed + move_mbleft() and moved to chars.c), move_right() (renamed + move_mbright() and moved to chars.c), do_home(), do_verbatim_input(), do_delete(), do_tab(), do_next_word(), do_input(), do_output(), get_buffer(), unget_input(), unget_kbinput(), get_input(), parse_kbinput(), diff --git a/src/chars.c b/src/chars.c index 02a1ca95..1e7acfb2 100644 --- a/src/chars.c +++ b/src/chars.c @@ -438,3 +438,40 @@ int parse_mbchar(const char *buf, char *chr return buf_mb_len; } + +/* Return the index in buf of the beginning of the multibyte character + * before the one at pos. */ +size_t move_mbleft(const char *buf, size_t pos) +{ + size_t pos_prev = pos; + + assert(str != NULL && pos <= strlen(buf)); + + /* There is no library function to move backward one multibyte + * character. Here is the naive, O(pos) way to do it. */ + while (TRUE) { + int buf_mb_len = parse_mbchar(buf + pos - pos_prev, NULL +#ifdef NANO_WIDE + , NULL +#endif + , NULL); + + if (pos_prev <= buf_mb_len) + break; + + pos_prev -= buf_mb_len; + } + + return pos - pos_prev; +} + +/* Return the index in buf of the beginning of the multibyte character + * after the one at pos. */ +size_t move_mbright(const char *buf, size_t pos) +{ + return pos + parse_mbchar(buf + pos, NULL +#ifdef NANO_WIDE + , NULL +#endif + , NULL); +} diff --git a/src/move.c b/src/move.c index cdd88e14..9afb2ef2 100644 --- a/src/move.c +++ b/src/move.c @@ -71,7 +71,7 @@ void do_home(void) if (!is_blank_mbchar(blank_mb)) break; - current_x = move_right(current->data, current_x); + current_x = move_mbright(current->data, current_x); } free(blank_mb); @@ -266,7 +266,7 @@ void do_left(bool allow_update) { size_t pww_save = placewewant; if (current_x > 0) - current_x = move_left(current->data, current_x); + current_x = move_mbleft(current->data, current_x); else if (current != fileage) { do_up(); current_x = strlen(current->data); @@ -288,7 +288,7 @@ void do_right(bool allow_update) assert(current_x <= strlen(current->data)); if (current->data[current_x] != '\0') - current_x = move_right(current->data, current_x); + current_x = move_mbright(current->data, current_x); else if (current->next != NULL) { do_down(); current_x = 0; diff --git a/src/nano.c b/src/nano.c index 7518e0de..d1016fe2 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1335,7 +1335,7 @@ void do_next_word(void) if (!is_alnum_mbchar(char_mb)) break; - current_x = move_right(current->data, current_x); + current_x = move_mbright(current->data, current_x); } /* Go until we find the first letter of the next word. */ @@ -1350,7 +1350,7 @@ void do_next_word(void) if (is_alnum_mbchar(char_mb)) break; - current_x = move_right(current->data, current_x); + current_x = move_mbright(current->data, current_x); } if (current->data[current_x] != '\0') diff --git a/src/proto.h b/src/proto.h index 10b452a3..c7aabeb6 100644 --- a/src/proto.h +++ b/src/proto.h @@ -183,6 +183,8 @@ int parse_mbchar(const char *buf, char *chr , bool *bad_chr #endif , size_t *col); +size_t move_mbleft(const char *buf, size_t pos); +size_t move_mbright(const char *buf, size_t pos); /* Public functions in color.c. */ #ifdef ENABLE_COLOR @@ -507,8 +509,6 @@ int regexp_bol_or_eol(const regex_t *preg, const char *string); int num_of_digits(int n); bool is_byte(unsigned int c); bool parse_num(const char *str, ssize_t *val); -size_t move_left(const char *buf, size_t pos); -size_t move_right(const char *buf, size_t pos); void align(char **strp); void null_at(char **data, size_t index); void unsunder(char *str, size_t true_len); diff --git a/src/utils.c b/src/utils.c index 104fc5d0..865a1f57 100644 --- a/src/utils.c +++ b/src/utils.c @@ -93,43 +93,6 @@ bool parse_num(const char *str, ssize_t *val) return TRUE; } -/* Return the index in buf of the beginning of the character before the - * one at pos. */ -size_t move_left(const char *buf, size_t pos) -{ - size_t pos_prev = pos; - - assert(str != NULL && pos <= strlen(buf)); - - /* There is no library function to move backward one multibyte - * character. Here is the naive, O(pos) way to do it. */ - while (TRUE) { - int buf_mb_len = parse_mbchar(buf + pos - pos_prev, NULL -#ifdef NANO_WIDE - , NULL -#endif - , NULL); - - if (pos_prev <= buf_mb_len) - break; - - pos_prev -= buf_mb_len; - } - - return pos - pos_prev; -} - -/* Return the index in buf of the beginning of the character after the - * one at pos. */ -size_t move_right(const char *buf, size_t pos) -{ - return pos + parse_mbchar(buf + pos, NULL -#ifdef NANO_WIDE - , NULL -#endif - , NULL); -} - /* Fix the memory allocation for a string. */ void align(char **strp) { diff --git a/src/winio.c b/src/winio.c index 5ae85bb6..ad4f5c54 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1818,7 +1818,7 @@ void do_statusbar_home(void) if (!is_blank_mbchar(blank_mb)) break; - statusbar_x = move_right(answer, statusbar_x); + statusbar_x = move_mbright(answer, statusbar_x); } free(blank_mb); @@ -1839,13 +1839,13 @@ void do_statusbar_end(void) void do_statusbar_right(void) { if (statusbar_x < statusbar_xend) - statusbar_x = move_right(answer, statusbar_x); + statusbar_x = move_mbright(answer, statusbar_x); } void do_statusbar_left(void) { if (statusbar_x > 0) - statusbar_x = move_left(answer, statusbar_x); + statusbar_x = move_mbleft(answer, statusbar_x); } void do_statusbar_backspace(void)