diff options
Diffstat (limited to 'src/nvim/search.c')
-rw-r--r-- | src/nvim/search.c | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/src/nvim/search.c b/src/nvim/search.c index 40d3f74103..9280bb6fa4 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -821,11 +821,10 @@ int searchit( pos->lnum, FALSE)); } } else { - --pos->col; - if (has_mbyte - && pos->lnum <= buf->b_ml.ml_line_count) { - ptr = ml_get_buf(buf, pos->lnum, FALSE); - pos->col -= (*mb_head_off)(ptr, ptr + pos->col); + pos->col--; + if (pos->lnum <= buf->b_ml.ml_line_count) { + ptr = ml_get_buf(buf, pos->lnum, false); + pos->col -= utf_head_off(ptr, ptr + pos->col); } } } else { @@ -1423,7 +1422,7 @@ int searchc(cmdarg_T *cap, int t_cmd) } else { if (col == 0) return FAIL; - col -= (*mb_head_off)(p, p + col - 1) + 1; + col -= utf_head_off(p, p + col - 1) + 1; } if (lastc_bytelen == 1) { if (p[col] == c && stop) { @@ -1446,15 +1445,14 @@ int searchc(cmdarg_T *cap, int t_cmd) } if (t_cmd) { - /* backup to before the character (possibly double-byte) */ + // Backup to before the character (possibly double-byte). col -= dir; - if (has_mbyte) { - if (dir < 0) - /* Landed on the search char which is lastc_bytelen long */ - col += lastc_bytelen - 1; - else - /* To previous char, which may be multi-byte. */ - col -= (*mb_head_off)(p, p + col); + if (dir < 0) { + // Landed on the search char which is lastc_bytelen long. + col += lastc_bytelen - 1; + } else { + // To previous char, which may be multi-byte. + col -= utf_head_off(p, p + col); } } curwin->w_cursor.col = col; @@ -1476,21 +1474,21 @@ pos_T *findmatch(oparg_T *oap, int initc) return findmatchlimit(oap, initc, 0, 0); } -/* - * Return TRUE if the character before "linep[col]" equals "ch". - * Return FALSE if "col" is zero. - * Update "*prevcol" to the column of the previous character, unless "prevcol" - * is NULL. - * Handles multibyte string correctly. - */ -static int check_prevcol(char_u *linep, int col, int ch, int *prevcol) +// Return true if the character before "linep[col]" equals "ch". +// Return false if "col" is zero. +// Update "*prevcol" to the column of the previous character, unless "prevcol" +// is NULL. +// Handles multibyte string correctly. +static bool check_prevcol(char_u *linep, int col, int ch, int *prevcol) { - --col; - if (col > 0 && has_mbyte) - col -= (*mb_head_off)(linep, linep + col); - if (prevcol) + col--; + if (col > 0) { + col -= utf_head_off(linep, linep + col); + } + if (prevcol) { *prevcol = col; - return (col >= 0 && linep[col] == ch) ? TRUE : FALSE; + } + return (col >= 0 && linep[col] == ch) ? true : false; } /* @@ -1797,9 +1795,8 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) if (lisp && comment_col != MAXCOL) pos.col = comment_col; } else { - --pos.col; - if (has_mbyte) - pos.col -= (*mb_head_off)(linep, linep + pos.col); + pos.col--; + pos.col -= utf_head_off(linep, linep + pos.col); } } else { /* forward search */ if (linep[pos.col] == NUL @@ -2386,8 +2383,7 @@ findpar ( // motion inclusive. if ((curwin->w_cursor.col = (colnr_T)STRLEN(line)) != 0) { curwin->w_cursor.col--; - curwin->w_cursor.col -= - (*mb_head_off)(line, line + curwin->w_cursor.col); + curwin->w_cursor.col -= utf_head_off(line, line + curwin->w_cursor.col); *pincl = true; } } else @@ -3694,8 +3690,8 @@ find_prev_quote( int n; while (col_start > 0) { - --col_start; - col_start -= (*mb_head_off)(line, line + col_start); + col_start--; + col_start -= utf_head_off(line, line + col_start); n = 0; if (escape != NULL) while (col_start - n > 0 && vim_strchr(escape, |