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
master
David Lawrence Ramsey 2005-01-14 21:50:32 +00:00
parent 1fe2eebf74
commit d24fbb760d
7 changed files with 50 additions and 48 deletions

View File

@ -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(),

View File

@ -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);
}

View File

@ -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;

View File

@ -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')

View File

@ -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);

View File

@ -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)
{

View File

@ -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)