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(),
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);
+}
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);
{
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);
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;
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. */
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')
, 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
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);
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)
{
if (!is_blank_mbchar(blank_mb))
break;
- statusbar_x = move_right(answer, statusbar_x);
+ statusbar_x = move_mbright(answer, statusbar_x);
}
free(blank_mb);
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)