diff options
Diffstat (limited to 'src/nvim/mbyte.c')
-rw-r--r-- | src/nvim/mbyte.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 65a1a8246c..0ee8e2bd85 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -550,7 +550,7 @@ size_t mb_string2cells(const char_u *str) size_t clen = 0; for (const char_u *p = str; *p != NUL; p += (*mb_ptr2len)(p)) { - clen += (*mb_ptr2cells)(p); + clen += utf_ptr2cells(p); } return clen; @@ -566,7 +566,9 @@ int utf_off2cells(unsigned off, unsigned max_off) /// Convert a UTF-8 byte sequence to a wide character /// /// If the sequence is illegal or truncated by a NUL then the first byte is -/// returned. Does not include composing characters for obvious reasons. +/// returned. +/// For an overlong sequence this may return zero. +/// Does not include composing characters for obvious reasons. /// /// @param[in] p String to convert. /// @@ -674,7 +676,7 @@ int mb_ptr2char_adv(const char_u **const pp) { int c; - c = (*mb_ptr2char)(*pp); + c = utf_ptr2char(*pp); *pp += (*mb_ptr2len)(*pp); return c; } @@ -687,7 +689,7 @@ int mb_cptr2char_adv(const char_u **pp) { int c; - c = (*mb_ptr2char)(*pp); + c = utf_ptr2char(*pp); *pp += utf_ptr2len(*pp); return c; } @@ -1708,13 +1710,13 @@ void mb_check_adjust_col(void *win_) win->w_cursor.col = len - 1; } // Move the cursor to the head byte. - win->w_cursor.col -= (*mb_head_off)(p, p + win->w_cursor.col); + win->w_cursor.col -= utf_head_off(p, p + win->w_cursor.col); } // Reset `coladd` when the cursor would be on the right half of a // double-wide character. if (win->w_cursor.coladd == 1 && p[win->w_cursor.col] != TAB - && vim_isprintc((*mb_ptr2char)(p + win->w_cursor.col)) + && vim_isprintc(utf_ptr2char(p + win->w_cursor.col)) && ptr2cells(p + win->w_cursor.col) > 1) { win->w_cursor.coladd = 0; } @@ -1827,8 +1829,8 @@ const char *mb_unescape(const char **const pp) */ bool mb_lefthalve(int row, int col) { - return (*mb_off2cells)(LineOffset[row] + col, - LineOffset[row] + screen_Columns) > 1; + return utf_off2cells(LineOffset[row] + col, + LineOffset[row] + screen_Columns) > 1; } /* @@ -2122,8 +2124,9 @@ static char_u *iconv_string(const vimconv_T *const vcp, char_u *str, * conversion from 'encoding' to something else. In other * situations we don't know what to skip anyway. */ *to++ = '?'; - if ((*mb_ptr2cells)((char_u *)from) > 1) + if (utf_ptr2cells((char_u *)from) > 1) { *to++ = '?'; + } l = utfc_ptr2len_len((const char_u *)from, (int)fromlen); from += l; fromlen -= l; |