From 2bddc4ca54e31a14b7e9799beda134217ae867e7 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Wed, 15 Aug 2018 22:02:33 +0300 Subject: Remove occurences of mb_head_off --- src/nvim/diff.c | 4 ++-- src/nvim/edit.c | 8 ++++---- src/nvim/ex_getln.c | 12 ++++++------ src/nvim/getchar.c | 2 +- src/nvim/macros.h | 2 +- src/nvim/mark.c | 2 +- src/nvim/mbyte.c | 2 +- src/nvim/mbyte.h | 1 - src/nvim/memline.c | 4 ++-- src/nvim/misc1.c | 4 ++-- src/nvim/normal.c | 6 +++--- src/nvim/ops.c | 6 +++--- src/nvim/path.c | 2 +- src/nvim/regexp.c | 2 +- src/nvim/regexp_nfa.c | 2 +- src/nvim/screen.c | 2 +- src/nvim/search.c | 14 +++++++------- src/nvim/spell.c | 2 +- src/nvim/syntax.c | 2 +- src/nvim/window.c | 2 +- 20 files changed, 40 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 878971a35c..cd0aa40ecd 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1965,8 +1965,8 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) if (has_mbyte) { // Move back to first byte of character in both lines (may // have "nn^" in line_org and "n^ in line_new). - si_org -= (*mb_head_off)(line_org, line_org + si_org); - si_new -= (*mb_head_off)(line_new, line_new + si_new); + si_org -= utf_head_off(line_org, line_org + si_org); + si_new -= utf_head_off(line_new, line_new + si_new); } if (*startp > si_org) { diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 085f12473e..82c74a00c5 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1561,7 +1561,7 @@ void display_dollar(colnr_T col) /* If on the last byte of a multi-byte move to the first byte. */ p = get_cursor_line_ptr(); - curwin->w_cursor.col -= (*mb_head_off)(p, p + col); + curwin->w_cursor.col -= utf_head_off(p, p + col); } curs_columns(FALSE); /* recompute w_wrow and w_wcol */ if (curwin->w_wcol < curwin->w_width) { @@ -3451,7 +3451,7 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) for (len = 0; p[len] != NUL && p[len] == ptr[len]; ++len) ; if (len > 0) - len -= (*mb_head_off)(p, p + len); + len -= utf_head_off(p, p + len); for (p += len; *p != NUL; MB_PTR_ADV(p)) { AppendCharToRedobuff(K_BS); } @@ -4593,10 +4593,10 @@ static int ins_complete(int c, bool enable_pum) int base_class; int head_off; - startcol -= (*mb_head_off)(line, line + startcol); + startcol -= utf_head_off(line, line + startcol); base_class = mb_get_class(line + startcol); while (--startcol >= 0) { - head_off = (*mb_head_off)(line, line + startcol); + head_off = utf_head_off(line, line + startcol); if (base_class != mb_get_class(line + startcol - head_off)) break; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 1810056a4a..4d3a3c3e96 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -726,7 +726,7 @@ static int command_line_execute(VimState *state, int key) s->i = (int)(s->xpc.xp_pattern - ccline.cmdbuff); while (--s->j > s->i) { if (has_mbyte) { - s->j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + s->j); + s->j -= utf_head_off(ccline.cmdbuff, ccline.cmdbuff + s->j); } if (vim_ispathsep(ccline.cmdbuff[s->j])) { found = true; @@ -748,7 +748,7 @@ static int command_line_execute(VimState *state, int key) s->i = (int)(s->xpc.xp_pattern - ccline.cmdbuff); while (--s->j > s->i) { if (has_mbyte) { - s->j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + s->j); + s->j -= utf_head_off(ccline.cmdbuff, ccline.cmdbuff + s->j); } if (vim_ispathsep(ccline.cmdbuff[s->j]) #ifdef BACKSLASH_IN_FILENAME @@ -1437,7 +1437,7 @@ static int command_line_handle_key(CommandLineState *s) do { --ccline.cmdpos; if (has_mbyte) { // move to first byte of char - ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, + ccline.cmdpos -= utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos); } ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); @@ -2271,7 +2271,7 @@ getexmodeline ( if (has_mbyte) { p = (char_u *)line_ga.ga_data; p[line_ga.ga_len] = NUL; - len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; + len = utf_head_off(p, p + line_ga.ga_len - 1) + 1; line_ga.ga_len -= len; } else { line_ga.ga_len--; @@ -3156,7 +3156,7 @@ void put_on_cmdline(char_u *str, int len, int redraw) i = 0; c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); while (ccline.cmdpos > 0 && utf_iscomposing(c)) { - i = (*mb_head_off)(ccline.cmdbuff, + i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; ccline.cmdpos -= i; len += i; @@ -3164,7 +3164,7 @@ void put_on_cmdline(char_u *str, int len, int redraw) } if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) { /* Check the previous character for Arabic combining pair. */ - i = (*mb_head_off)(ccline.cmdbuff, + i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; if (arabic_combine(utf_ptr2char(ccline.cmdbuff + ccline.cmdpos - i), c)) { diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index b57e1f6558..8c6c3dfd7e 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2133,7 +2133,7 @@ static int vgetorpeek(int advance) /* Correct when the cursor is on the right halve * of a double-wide character. */ ptr = get_cursor_line_ptr(); - col -= (*mb_head_off)(ptr, ptr + col); + col -= utf_head_off(ptr, ptr + col); if ((*mb_ptr2cells)(ptr + col) > 1) --curwin->w_wcol; } diff --git a/src/nvim/macros.h b/src/nvim/macros.h index b02af723b4..3416bc142e 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -118,7 +118,7 @@ // Advance multi-byte pointer, do not skip over composing chars. # define MB_CPTR_ADV(p) (p += utf_ptr2len(p)) // Backup multi-byte pointer. Only use with "p" > "s" ! -# define MB_PTR_BACK(s, p) (p -= mb_head_off((char_u *)s, (char_u *)p - 1) + 1) +# define MB_PTR_BACK(s, p) (p -= utf_head_off((char_u *)s, (char_u *)p - 1) + 1) // get length of multi-byte char, not including composing chars # define MB_CPTR2LEN(p) utf_ptr2len(p) diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 3861d9ceb8..5366fa4b7f 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -1468,7 +1468,7 @@ void mark_mb_adjustpos(buf_T *buf, pos_T *lp) if (*p == NUL || (int)STRLEN(p) < lp->col) { lp->col = 0; } else { - lp->col -= (*mb_head_off)(p, p + lp->col); + lp->col -= utf_head_off(p, p + lp->col); } // Reset "coladd" when the cursor would be on the right half of a // double-wide character. diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 94bf7fb985..11c1897153 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -1710,7 +1710,7 @@ 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 diff --git a/src/nvim/mbyte.h b/src/nvim/mbyte.h index 5f48e1783e..6ec25edc4a 100644 --- a/src/nvim/mbyte.h +++ b/src/nvim/mbyte.h @@ -53,7 +53,6 @@ enum { MAX_MCO = 6 }; #define mb_ptr2cells utf_ptr2cells #define mb_ptr2cells_len utf_ptr2cells_len #define mb_char2cells utf_char2cells -#define mb_head_off utf_head_off /// Flags for vimconv_T typedef enum { diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 3d5f4e8f3a..ca89b7a345 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -4042,7 +4042,7 @@ int dec(pos_T *lp) lp->col--; if (has_mbyte) { p = ml_get(lp->lnum); - lp->col -= (*mb_head_off)(p, p + lp->col); + lp->col -= utf_head_off(p, p + lp->col); } return 0; } @@ -4051,7 +4051,7 @@ int dec(pos_T *lp) p = ml_get(lp->lnum); lp->col = (colnr_T)STRLEN(p); if (has_mbyte) { - lp->col -= (*mb_head_off)(p, p + lp->col); + lp->col -= utf_head_off(p, p + lp->col); } return 1; } diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 84d8c995a6..93886351ac 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -548,7 +548,7 @@ open_line ( /* blank-out any other chars from the old leader. */ while (--p >= leader) { - int l = mb_head_off(leader, p); + int l = utf_head_off(leader, p); if (l > 1) { p -= l; @@ -1648,7 +1648,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) curwin->w_cursor.coladd = 0; if (has_mbyte) curwin->w_cursor.col -= - (*mb_head_off)(oldp, oldp + curwin->w_cursor.col); + utf_head_off(oldp, oldp + curwin->w_cursor.col); } count = oldlen - col; movelen = 1; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 225fe4aa9a..0cd4486d40 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -2858,7 +2858,7 @@ static void find_start_of_word(pos_T *pos) while (pos->col > 0) { col = pos->col - 1; - col -= (*mb_head_off)(line, line + col); + col -= utf_head_off(line, line + col); if (get_mouse_class(line + col) != cclass) break; pos->col = col; @@ -2878,7 +2878,7 @@ static void find_end_of_word(pos_T *pos) line = ml_get(pos->lnum); if (*p_sel == 'e' && pos->col > 0) { --pos->col; - pos->col -= (*mb_head_off)(line, line + pos->col); + pos->col -= utf_head_off(line, line + pos->col); } cclass = get_mouse_class(line + pos->col); while (line[pos->col] != NUL) { @@ -3062,7 +3062,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, /* Remember class of character under cursor. */ this_class = mb_get_class(ptr + col); while (col > 0 && this_class != 0) { - prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); + prevcol = col - 1 - utf_head_off(ptr, ptr + col - 1); prev_class = mb_get_class(ptr + prevcol); if (this_class != prev_class && (i == 0 diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 7defde731a..410cddb2be 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -525,7 +525,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def // Avoid starting halfway through a multi-byte character. if (b_insert) { - off = (*mb_head_off)(oldp, oldp + offset + spaces); + off = utf_head_off(oldp, oldp + offset + spaces); } else { off = (*mb_off_next)(oldp, oldp + offset); offset += off; @@ -2435,7 +2435,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) /* Don't add space for double-wide * char; endcol will be on last byte * of multi-byte char. */ - && (*mb_head_off)(p, p + endcol) == 0 + && utf_head_off(p, p + endcol) == 0 )) { if (oap->start.lnum == oap->end.lnum && oap->start.col == oap->end.col) { @@ -2992,7 +2992,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) bd.startspaces = incr - bd.endspaces; --bd.textcol; delcount = 1; - bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol); + bd.textcol -= utf_head_off(oldp, oldp + bd.textcol); if (oldp[bd.textcol] != TAB) { /* Only a Tab can be split into spaces. Other * characters will have to be moved to after the diff --git a/src/nvim/path.c b/src/nvim/path.c index cc4a5f62a7..08b904534b 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1819,7 +1819,7 @@ void path_fix_case(char_u *name) int after_pathsep(const char *b, const char *p) { return p > b && vim_ispathsep(p[-1]) - && (!has_mbyte || (*mb_head_off)((char_u *)b, (char_u *)p - 1) == 0); + && (!has_mbyte || utf_head_off((char_u *)b, (char_u *)p - 1) == 0); } /* diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 98d737c9a9..76936beaa5 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3653,7 +3653,7 @@ static long regtry(bt_regprog_T *prog, colnr_T col) static int reg_prev_class(void) { if (reginput > regline) { - return mb_get_class_tab(reginput - 1 - (*mb_head_off)(regline, + return mb_get_class_tab(reginput - 1 - utf_head_off(regline, reginput - 1), rex.reg_buf->b_chartab); } diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 29191c14a8..b52b39c722 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -4640,7 +4640,7 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T if ((int)(reginput - regline) >= state->val) { reginput -= state->val; if (has_mbyte) - reginput -= mb_head_off(regline, reginput); + reginput -= utf_head_off(regline, reginput); } else reginput = regline; } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index ec48bf5dcf..9d92c9aa71 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3430,7 +3430,7 @@ win_line ( // Found last space before word: check for line break. if (wp->w_p_lbr && c0 == c && vim_isbreak(c) && !vim_isbreak((int)(*ptr))) { - int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0; + int mb_off = has_mbyte ? utf_head_off(line, ptr - 1) : 0; char_u *p = ptr - (mb_off + 1); // TODO: is passing p for start of the line OK? n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, NULL) - 1; diff --git a/src/nvim/search.c b/src/nvim/search.c index 95929f0eb4..10d7d3320d 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -821,7 +821,7 @@ int searchit( 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 -= utf_head_off(ptr, ptr + pos->col); } } } else { @@ -1419,7 +1419,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) { @@ -1450,7 +1450,7 @@ int searchc(cmdarg_T *cap, int t_cmd) col += lastc_bytelen - 1; else /* To previous char, which may be multi-byte. */ - col -= (*mb_head_off)(p, p + col); + col -= utf_head_off(p, p + col); } } curwin->w_cursor.col = col; @@ -1483,7 +1483,7 @@ static int check_prevcol(char_u *linep, int col, int ch, int *prevcol) { --col; if (col > 0 && has_mbyte) - col -= (*mb_head_off)(linep, linep + col); + col -= utf_head_off(linep, linep + col); if (prevcol) *prevcol = col; return (col >= 0 && linep[col] == ch) ? TRUE : FALSE; @@ -1795,7 +1795,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) } else { --pos.col; if (has_mbyte) - pos.col -= (*mb_head_off)(linep, linep + pos.col); + pos.col -= utf_head_off(linep, linep + pos.col); } } else { /* forward search */ if (linep[pos.col] == NUL @@ -2386,7 +2386,7 @@ findpar ( 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); + utf_head_off(line, line + curwin->w_cursor.col); *pincl = true; } } else @@ -3692,7 +3692,7 @@ find_prev_quote( while (col_start > 0) { --col_start; - col_start -= (*mb_head_off)(line, line + col_start); + col_start -= utf_head_off(line, line + col_start); n = 0; if (escape != NULL) while (col_start - n > 0 && vim_strchr(escape, diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 1cb679245b..35dd41591c 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -688,7 +688,7 @@ static void find_word(matchinf_T *mip, int mode) arridx = endidx[endidxcnt]; wlen = endlen[endidxcnt]; - if ((*mb_head_off)(ptr, ptr + wlen) > 0) + if (utf_head_off(ptr, ptr + wlen) > 0) continue; // not at first byte of character if (spell_iswordp(ptr + wlen, mip->mi_win)) { if (slang->sl_compprog == NULL && !slang->sl_nobreak) diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 3cb998b805..64d80d722a 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -1730,7 +1730,7 @@ static int syn_current_attr( && (current_col == 0 || !vim_iswordp_buf(line + current_col - 1 - (has_mbyte - ? (*mb_head_off)(line, line + current_col - 1) + ? utf_head_off(line, line + current_col - 1) : 0) , syn_buf))) { syn_id = check_keyword_id(line, (int)current_col, diff --git a/src/nvim/window.c b/src/nvim/window.c index 8239061a0c..fa963d790d 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5130,7 +5130,7 @@ file_name_in_line ( * Go one char back to ":" before "//" even when ':' is not in 'isfname'. */ while (ptr > line) { - if (has_mbyte && (len = (size_t)((*mb_head_off)(line, ptr - 1))) > 0) + if (has_mbyte && (len = (size_t)(utf_head_off(line, ptr - 1))) > 0) ptr -= len + 1; else if (vim_isfilec(ptr[-1]) || ((options & FNAME_HYP) && path_is_url((char *)ptr - 1))) -- cgit From 30392b635689a5f25421c17ead79e521863c8b57 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Wed, 15 Aug 2018 22:46:48 +0300 Subject: Remove has_mbyte from lines near changes in parent commit --- src/nvim/diff.c | 10 ++++----- src/nvim/edit.c | 34 +++++++++++-------------------- src/nvim/ex_getln.c | 31 +++++++++------------------- src/nvim/getchar.c | 2 +- src/nvim/memline.c | 14 ++++--------- src/nvim/misc1.c | 4 +--- src/nvim/normal.c | 56 +++++++++++++++++---------------------------------- src/nvim/ops.c | 2 +- src/nvim/path.c | 2 +- src/nvim/regexp_nfa.c | 3 +-- src/nvim/screen.c | 2 +- src/nvim/search.c | 22 +++++++++----------- src/nvim/syntax.c | 4 +--- src/nvim/window.c | 2 +- 14 files changed, 66 insertions(+), 122 deletions(-) (limited to 'src') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index cd0aa40ecd..4bfe67c9d3 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1962,12 +1962,10 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) } } - if (has_mbyte) { - // Move back to first byte of character in both lines (may - // have "nn^" in line_org and "n^ in line_new). - si_org -= utf_head_off(line_org, line_org + si_org); - si_new -= utf_head_off(line_new, line_new + si_new); - } + // Move back to first byte of character in both lines (may + // have "nn^" in line_org and "n^ in line_new). + si_org -= utf_head_off(line_org, line_org + si_org); + si_new -= utf_head_off(line_new, line_new + si_new); if (*startp > si_org) { *startp = si_org; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 82c74a00c5..c60f85ed4c 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1556,13 +1556,10 @@ void display_dollar(colnr_T col) save_col = curwin->w_cursor.col; curwin->w_cursor.col = col; - if (has_mbyte) { - char_u *p; - /* If on the last byte of a multi-byte move to the first byte. */ - p = get_cursor_line_ptr(); - curwin->w_cursor.col -= utf_head_off(p, p + col); - } + /* If on the last byte of a multi-byte move to the first byte. */ + char_u *p = get_cursor_line_ptr(); + curwin->w_cursor.col -= utf_head_off(p, p + col); curs_columns(FALSE); /* recompute w_wrow and w_wcol */ if (curwin->w_wcol < curwin->w_width) { edit_putchar('$', FALSE); @@ -4589,22 +4586,15 @@ static int ins_complete(int c, bool enable_pum) } else { /* Search the point of change class of multibyte character * or not a word single byte character backward. */ - if (has_mbyte) { - int base_class; - int head_off; - - startcol -= utf_head_off(line, line + startcol); - base_class = mb_get_class(line + startcol); - while (--startcol >= 0) { - head_off = utf_head_off(line, line + startcol); - if (base_class != mb_get_class(line + startcol - - head_off)) - break; - startcol -= head_off; - } - } else - while (--startcol >= 0 && vim_iswordc(line[startcol])) - ; + startcol -= utf_head_off(line, line + startcol); + int base_class = mb_get_class(line + startcol); + while (--startcol >= 0) { + int head_off = utf_head_off(line, line + startcol); + if (base_class != mb_get_class(line + startcol + - head_off)) + break; + startcol -= head_off; + } compl_col += ++startcol; compl_length = (int)curs_col - startcol; if (compl_length == 1) { diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 4d3a3c3e96..b15dea00fe 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -725,9 +725,7 @@ static int command_line_execute(VimState *state, int key) s->j = ccline.cmdpos; s->i = (int)(s->xpc.xp_pattern - ccline.cmdbuff); while (--s->j > s->i) { - if (has_mbyte) { - s->j -= utf_head_off(ccline.cmdbuff, ccline.cmdbuff + s->j); - } + s->j -= utf_head_off(ccline.cmdbuff, ccline.cmdbuff + s->j); if (vim_ispathsep(ccline.cmdbuff[s->j])) { found = true; break; @@ -747,9 +745,7 @@ static int command_line_execute(VimState *state, int key) s->j = ccline.cmdpos - 1; s->i = (int)(s->xpc.xp_pattern - ccline.cmdbuff); while (--s->j > s->i) { - if (has_mbyte) { - s->j -= utf_head_off(ccline.cmdbuff, ccline.cmdbuff + s->j); - } + s->j -= utf_head_off(ccline.cmdbuff, ccline.cmdbuff + s->j); if (vim_ispathsep(ccline.cmdbuff[s->j]) #ifdef BACKSLASH_IN_FILENAME && vim_strchr((const char_u *)" *?[{`$%#", ccline.cmdbuff[s->j + 1]) @@ -1436,19 +1432,16 @@ static int command_line_handle_key(CommandLineState *s) } do { --ccline.cmdpos; - if (has_mbyte) { // move to first byte of char - ccline.cmdpos -= utf_head_off(ccline.cmdbuff, - ccline.cmdbuff + ccline.cmdpos); - } + // Move to first byte of possibly multibyte char. + ccline.cmdpos -= utf_head_off(ccline.cmdbuff, + ccline.cmdbuff + ccline.cmdpos); ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); } while (ccline.cmdpos > 0 && (s->c == K_S_LEFT || s->c == K_C_LEFT || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); - if (has_mbyte) { - set_cmdspos_cursor(); - } + set_cmdspos_cursor(); return command_line_not_changed(s); @@ -2268,14 +2261,10 @@ getexmodeline ( if (c1 == BS || c1 == K_BS || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) { if (!GA_EMPTY(&line_ga)) { - if (has_mbyte) { - p = (char_u *)line_ga.ga_data; - p[line_ga.ga_len] = NUL; - len = utf_head_off(p, p + line_ga.ga_len - 1) + 1; - line_ga.ga_len -= len; - } else { - line_ga.ga_len--; - } + p = (char_u *)line_ga.ga_data; + p[line_ga.ga_len] = NUL; + len = utf_head_off(p, p + line_ga.ga_len - 1) + 1; + line_ga.ga_len -= len; goto redraw; } continue; diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 8c6c3dfd7e..c8f29435e3 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2129,7 +2129,7 @@ static int vgetorpeek(int advance) curwin->w_wcol = curwin->w_width - 1; col = curwin->w_cursor.col - 1; } - if (has_mbyte && col > 0 && curwin->w_wcol > 0) { + if (col > 0 && curwin->w_wcol > 0) { /* Correct when the cursor is on the right halve * of a double-wide character. */ ptr = get_cursor_line_ptr(); diff --git a/src/nvim/memline.c b/src/nvim/memline.c index ca89b7a345..6831e48719 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -4035,24 +4035,18 @@ int incl(pos_T *lp) int dec(pos_T *lp) { - char_u *p; - lp->coladd = 0; if (lp->col > 0) { // still within line lp->col--; - if (has_mbyte) { - p = ml_get(lp->lnum); - lp->col -= utf_head_off(p, p + lp->col); - } + char_u *p = ml_get(lp->lnum); + lp->col -= utf_head_off(p, p + lp->col); return 0; } if (lp->lnum > 1) { // there is a prior line lp->lnum--; - p = ml_get(lp->lnum); + char_u *p = ml_get(lp->lnum); lp->col = (colnr_T)STRLEN(p); - if (has_mbyte) { - lp->col -= utf_head_off(p, p + lp->col); - } + lp->col -= utf_head_off(p, p + lp->col); return 1; } return -1; // at start of file diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 93886351ac..08d1df7f08 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -1646,9 +1646,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) ) { --curwin->w_cursor.col; curwin->w_cursor.coladd = 0; - if (has_mbyte) - curwin->w_cursor.col -= - utf_head_off(oldp, oldp + curwin->w_cursor.col); + curwin->w_cursor.col -= utf_head_off(oldp, oldp + curwin->w_cursor.col); } count = oldlen - col; movelen = 1; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 0cd4486d40..d36c0e42a4 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3058,47 +3058,29 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, /* * 2. Back up to start of identifier/string. */ - if (has_mbyte) { - /* Remember class of character under cursor. */ - this_class = mb_get_class(ptr + col); - while (col > 0 && this_class != 0) { - prevcol = col - 1 - utf_head_off(ptr, ptr + col - 1); - prev_class = mb_get_class(ptr + prevcol); - if (this_class != prev_class - && (i == 0 - || prev_class == 0 - || (find_type & FIND_IDENT)) - ) - break; - col = prevcol; - } - - /* If we don't want just any old string, or we've found an - * identifier, stop searching. */ - if (this_class > 2) - this_class = 2; - if (!(find_type & FIND_STRING) || this_class == 2) - break; - } else { - while (col > 0 - && ((i == 0 - ? vim_iswordc(ptr[col - 1]) - : (!ascii_iswhite(ptr[col - 1]) - && (!(find_type & FIND_IDENT) - || !vim_iswordc(ptr[col - 1])))) - )) - --col; - - /* If we don't want just any old string, or we've found an - * identifier, stop searching. */ - if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) + /* Remember class of character under cursor. */ + this_class = mb_get_class(ptr + col); + while (col > 0 && this_class != 0) { + prevcol = col - 1 - utf_head_off(ptr, ptr + col - 1); + prev_class = mb_get_class(ptr + prevcol); + if (this_class != prev_class + && (i == 0 + || prev_class == 0 + || (find_type & FIND_IDENT)) + ) break; + col = prevcol; } + + /* If we don't want just any old string, or we've found an + * identifier, stop searching. */ + if (this_class > 2) + this_class = 2; + if (!(find_type & FIND_STRING) || this_class == 2) + break; } - if (ptr[col] == NUL || (i == 0 && ( - has_mbyte ? this_class != 2 : - !vim_iswordc(ptr[col])))) { + if (ptr[col] == NUL || (i == 0 && this_class != 2)) { /* * didn't find an identifier or string */ diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 410cddb2be..dbdab4026d 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -520,7 +520,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def } } - if (has_mbyte && spaces > 0) { + if (spaces > 0) { int off; // Avoid starting halfway through a multi-byte character. diff --git a/src/nvim/path.c b/src/nvim/path.c index 08b904534b..eeb374cf44 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1819,7 +1819,7 @@ void path_fix_case(char_u *name) int after_pathsep(const char *b, const char *p) { return p > b && vim_ispathsep(p[-1]) - && (!has_mbyte || utf_head_off((char_u *)b, (char_u *)p - 1) == 0); + && utf_head_off((char_u *)b, (char_u *)p - 1) == 0; } /* diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index b52b39c722..c81121286d 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -4639,8 +4639,7 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T } if ((int)(reginput - regline) >= state->val) { reginput -= state->val; - if (has_mbyte) - reginput -= utf_head_off(regline, reginput); + reginput -= utf_head_off(regline, reginput); } else reginput = regline; } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 9d92c9aa71..b79e8f4546 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3430,7 +3430,7 @@ win_line ( // Found last space before word: check for line break. if (wp->w_p_lbr && c0 == c && vim_isbreak(c) && !vim_isbreak((int)(*ptr))) { - int mb_off = has_mbyte ? utf_head_off(line, ptr - 1) : 0; + int mb_off = utf_head_off(line, ptr - 1); char_u *p = ptr - (mb_off + 1); // TODO: is passing p for start of the line OK? n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, NULL) - 1; diff --git a/src/nvim/search.c b/src/nvim/search.c index 10d7d3320d..8e2c23b006 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -818,8 +818,7 @@ int searchit( } } else { --pos->col; - if (has_mbyte - && pos->lnum <= buf->b_ml.ml_line_count) { + 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); } @@ -1444,14 +1443,12 @@ int searchc(cmdarg_T *cap, int t_cmd) if (t_cmd) { /* 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 -= utf_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; @@ -1482,7 +1479,7 @@ pos_T *findmatch(oparg_T *oap, int initc) static int check_prevcol(char_u *linep, int col, int ch, int *prevcol) { --col; - if (col > 0 && has_mbyte) + if (col > 0) col -= utf_head_off(linep, linep + col); if (prevcol) *prevcol = col; @@ -1794,8 +1791,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) pos.col = comment_col; } else { --pos.col; - if (has_mbyte) - pos.col -= utf_head_off(linep, linep + pos.col); + pos.col -= utf_head_off(linep, linep + pos.col); } } else { /* forward search */ if (linep[pos.col] == NUL diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 64d80d722a..7ee26da5fe 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -1729,9 +1729,7 @@ static int syn_current_attr( if (vim_iswordp_buf(line + current_col, syn_buf) && (current_col == 0 || !vim_iswordp_buf(line + current_col - 1 - - (has_mbyte - ? utf_head_off(line, line + current_col - 1) - : 0) + - utf_head_off(line, line + current_col - 1) , syn_buf))) { syn_id = check_keyword_id(line, (int)current_col, &endcol, &flags, &next_list, cur_si, diff --git a/src/nvim/window.c b/src/nvim/window.c index fa963d790d..07953212c5 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5130,7 +5130,7 @@ file_name_in_line ( * Go one char back to ":" before "//" even when ':' is not in 'isfname'. */ while (ptr > line) { - if (has_mbyte && (len = (size_t)(utf_head_off(line, ptr - 1))) > 0) + if ((len = (size_t)(utf_head_off(line, ptr - 1))) > 0) ptr -= len + 1; else if (vim_isfilec(ptr[-1]) || ((options & FNAME_HYP) && path_is_url((char *)ptr - 1))) -- cgit From d110c6d7907d6f27f32b1d2bd91ffee7ef6097f4 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Thu, 16 Aug 2018 05:09:21 +0300 Subject: lint: cleanup after parent commits --- src/nvim/edit.c | 18 +++++++++--------- src/nvim/ex_getln.c | 13 +++++-------- src/nvim/getchar.c | 9 +++++---- src/nvim/macros.h | 3 ++- src/nvim/normal.c | 38 +++++++++++++++++++------------------- src/nvim/ops.c | 9 ++++----- src/nvim/regexp.c | 3 +-- src/nvim/regexp_nfa.c | 3 ++- src/nvim/search.c | 46 +++++++++++++++++++++++----------------------- src/nvim/spell.c | 3 ++- src/nvim/syntax.c | 14 ++++++-------- src/nvim/window.c | 11 ++++++----- 12 files changed, 84 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/nvim/edit.c b/src/nvim/edit.c index c60f85ed4c..c8061d82e4 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1557,10 +1557,10 @@ void display_dollar(colnr_T col) save_col = curwin->w_cursor.col; curwin->w_cursor.col = col; - /* If on the last byte of a multi-byte move to the first byte. */ + // If on the last byte of a multi-byte move to the first byte. char_u *p = get_cursor_line_ptr(); curwin->w_cursor.col -= utf_head_off(p, p + col); - curs_columns(FALSE); /* recompute w_wrow and w_wcol */ + curs_columns(false); // Recompute w_wrow and w_wcol if (curwin->w_wcol < curwin->w_width) { edit_putchar('$', FALSE); dollar_vcol = curwin->w_virtcol; @@ -3445,10 +3445,10 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) } if (compl_orig_text != NULL) { p = compl_orig_text; - for (len = 0; p[len] != NUL && p[len] == ptr[len]; ++len) - ; - if (len > 0) + for (len = 0; p[len] != NUL && p[len] == ptr[len]; len++) {} + if (len > 0) { len -= utf_head_off(p, p + len); + } for (p += len; *p != NUL; MB_PTR_ADV(p)) { AppendCharToRedobuff(K_BS); } @@ -4584,15 +4584,15 @@ static int ins_complete(int c, bool enable_pum) compl_col += curs_col; compl_length = 0; } else { - /* Search the point of change class of multibyte character - * or not a word single byte character backward. */ + // Search the point of change class of multibyte character + // or not a word single byte character backward. startcol -= utf_head_off(line, line + startcol); int base_class = mb_get_class(line + startcol); while (--startcol >= 0) { int head_off = utf_head_off(line, line + startcol); - if (base_class != mb_get_class(line + startcol - - head_off)) + if (base_class != mb_get_class(line + startcol - head_off)) { break; + } startcol -= head_off; } compl_col += ++startcol; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index b15dea00fe..b4509f9e92 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1431,7 +1431,7 @@ static int command_line_handle_key(CommandLineState *s) return command_line_not_changed(s); } do { - --ccline.cmdpos; + ccline.cmdpos--; // Move to first byte of possibly multibyte char. ccline.cmdpos -= utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos); @@ -3145,18 +3145,15 @@ void put_on_cmdline(char_u *str, int len, int redraw) i = 0; c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); while (ccline.cmdpos > 0 && utf_iscomposing(c)) { - i = utf_head_off(ccline.cmdbuff, - ccline.cmdbuff + ccline.cmdpos - 1) + 1; + i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; ccline.cmdpos -= i; len += i; c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); } if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) { - /* Check the previous character for Arabic combining pair. */ - i = utf_head_off(ccline.cmdbuff, - ccline.cmdbuff + ccline.cmdpos - 1) + 1; - if (arabic_combine(utf_ptr2char(ccline.cmdbuff - + ccline.cmdpos - i), c)) { + // Check the previous character for Arabic combining pair. + i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; + if (arabic_combine(utf_ptr2char(ccline.cmdbuff + ccline.cmdpos - i), c)) { ccline.cmdpos -= i; len += i; } else diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index c8f29435e3..0379b1cadb 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2130,12 +2130,13 @@ static int vgetorpeek(int advance) col = curwin->w_cursor.col - 1; } if (col > 0 && curwin->w_wcol > 0) { - /* Correct when the cursor is on the right halve - * of a double-wide character. */ + // Correct when the cursor is on the right halve + // of a double-wide character. ptr = get_cursor_line_ptr(); col -= utf_head_off(ptr, ptr + col); - if ((*mb_ptr2cells)(ptr + col) > 1) - --curwin->w_wcol; + if (utf_ptr2cells(ptr + col) > 1) { + curwin->w_wcol--; + } } } setcursor(); diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 3416bc142e..d447bff765 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -118,7 +118,8 @@ // Advance multi-byte pointer, do not skip over composing chars. # define MB_CPTR_ADV(p) (p += utf_ptr2len(p)) // Backup multi-byte pointer. Only use with "p" > "s" ! -# define MB_PTR_BACK(s, p) (p -= utf_head_off((char_u *)s, (char_u *)p - 1) + 1) +# define MB_PTR_BACK(s, p) \ + (p -= utf_head_off((char_u *)s, (char_u *)p - 1) + 1) // get length of multi-byte char, not including composing chars # define MB_CPTR2LEN(p) utf_ptr2len(p) diff --git a/src/nvim/normal.c b/src/nvim/normal.c index d36c0e42a4..8fdc660b68 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -2859,8 +2859,9 @@ static void find_start_of_word(pos_T *pos) while (pos->col > 0) { col = pos->col - 1; col -= utf_head_off(line, line + col); - if (get_mouse_class(line + col) != cclass) + if (get_mouse_class(line + col) != cclass) { break; + } pos->col = col; } } @@ -2877,7 +2878,7 @@ static void find_end_of_word(pos_T *pos) line = ml_get(pos->lnum); if (*p_sel == 'e' && pos->col > 0) { - --pos->col; + pos->col--; pos->col -= utf_head_off(line, line + pos->col); } cclass = get_mouse_class(line + pos->col); @@ -3055,39 +3056,38 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, ++col; - /* - * 2. Back up to start of identifier/string. - */ - /* Remember class of character under cursor. */ + // + // 2. Back up to start of identifier/string. + // + // Remember class of character under cursor. this_class = mb_get_class(ptr + col); while (col > 0 && this_class != 0) { prevcol = col - 1 - utf_head_off(ptr, ptr + col - 1); prev_class = mb_get_class(ptr + prevcol); if (this_class != prev_class - && (i == 0 - || prev_class == 0 - || (find_type & FIND_IDENT)) - ) + && (i == 0 || prev_class == 0 || (find_type & FIND_IDENT))) { break; + } col = prevcol; } - /* If we don't want just any old string, or we've found an - * identifier, stop searching. */ - if (this_class > 2) + // If we don't want just any old string, or we've found an + // identifier, stop searching. + if (this_class > 2) { this_class = 2; - if (!(find_type & FIND_STRING) || this_class == 2) + } + if (!(find_type & FIND_STRING) || this_class == 2) { break; + } } if (ptr[col] == NUL || (i == 0 && this_class != 2)) { - /* - * didn't find an identifier or string - */ - if (find_type & FIND_STRING) + // Didn't find an identifier or string. + if (find_type & FIND_STRING) { EMSG(_("E348: No string under cursor")); - else + } else { EMSG(_(e_noident)); + } return 0; } ptr += col; diff --git a/src/nvim/ops.c b/src/nvim/ops.c index dbdab4026d..a3fd6e11fd 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2432,11 +2432,10 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) if (virtual_op) { getvcol(curwin, &oap->end, &cs, NULL, &ce); if (p[endcol] == NUL || (cs + oap->end.coladd < ce - /* Don't add space for double-wide - * char; endcol will be on last byte - * of multi-byte char. */ - && utf_head_off(p, p + endcol) == 0 - )) { + // Don't add space for double-wide + // char; endcol will be on last byte + // of multi-byte char. + && utf_head_off(p, p + endcol) == 0)) { if (oap->start.lnum == oap->end.lnum && oap->start.col == oap->end.col) { /* Special case: inside a single char */ diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 76936beaa5..bbc161ee3e 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3653,8 +3653,7 @@ static long regtry(bt_regprog_T *prog, colnr_T col) static int reg_prev_class(void) { if (reginput > regline) { - return mb_get_class_tab(reginput - 1 - utf_head_off(regline, - reginput - 1), + return mb_get_class_tab(reginput - 1 - utf_head_off(regline, reginput - 1), rex.reg_buf->b_chartab); } return -1; diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index c81121286d..3be1f3d2f3 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -4640,8 +4640,9 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T if ((int)(reginput - regline) >= state->val) { reginput -= state->val; reginput -= utf_head_off(regline, reginput); - } else + } else { reginput = regline; + } } } diff --git a/src/nvim/search.c b/src/nvim/search.c index 8e2c23b006..97975c037b 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -817,9 +817,9 @@ int searchit( pos->lnum, FALSE)); } } else { - --pos->col; + pos->col--; if (pos->lnum <= buf->b_ml.ml_line_count) { - ptr = ml_get_buf(buf, pos->lnum, FALSE); + ptr = ml_get_buf(buf, pos->lnum, false); pos->col -= utf_head_off(ptr, ptr + pos->col); } } @@ -1441,14 +1441,15 @@ 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 (dir < 0) - /* Landed on the search char which is lastc_bytelen long */ + 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. */ + } else { + // To previous char, which may be multi-byte. col -= utf_head_off(p, p + col); + } } curwin->w_cursor.col = col; @@ -1469,21 +1470,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) + col--; + if (col > 0) { col -= utf_head_off(linep, linep + col); - if (prevcol) + } + if (prevcol) { *prevcol = col; - return (col >= 0 && linep[col] == ch) ? TRUE : FALSE; + } + return (col >= 0 && linep[col] == ch) ? true : false; } /* @@ -1790,7 +1791,7 @@ 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; + pos.col--; pos.col -= utf_head_off(linep, linep + pos.col); } } else { /* forward search */ @@ -2381,8 +2382,7 @@ findpar ( // motion inclusive. if ((curwin->w_cursor.col = (colnr_T)STRLEN(line)) != 0) { curwin->w_cursor.col--; - curwin->w_cursor.col -= - utf_head_off(line, line + curwin->w_cursor.col); + curwin->w_cursor.col -= utf_head_off(line, line + curwin->w_cursor.col); *pincl = true; } } else @@ -3687,7 +3687,7 @@ find_prev_quote( int n; while (col_start > 0) { - --col_start; + col_start--; col_start -= utf_head_off(line, line + col_start); n = 0; if (escape != NULL) diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 35dd41591c..f72c47bd15 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -688,8 +688,9 @@ static void find_word(matchinf_T *mip, int mode) arridx = endidx[endidxcnt]; wlen = endlen[endidxcnt]; - if (utf_head_off(ptr, ptr + wlen) > 0) + if (utf_head_off(ptr, ptr + wlen) > 0) { continue; // not at first byte of character + } if (spell_iswordp(ptr + wlen, mip->mi_win)) { if (slang->sl_compprog == NULL && !slang->sl_nobreak) continue; // next char is a word character diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 7ee26da5fe..332c50129e 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -1726,14 +1726,12 @@ static int syn_current_attr( */ if (do_keywords) { line = syn_getcurline(); - if (vim_iswordp_buf(line + current_col, syn_buf) - && (current_col == 0 - || !vim_iswordp_buf(line + current_col - 1 - - utf_head_off(line, line + current_col - 1) - , syn_buf))) { - syn_id = check_keyword_id(line, (int)current_col, - &endcol, &flags, &next_list, cur_si, - &cchar); + const char_u *cur_pos = line + current_col; + if (vim_iswordp_buf(cur_pos, syn_buf) + && (current_col == 0 || !vim_iswordp_buf( + cur_pos - 1 - utf_head_off(line, cur_pos - 1), syn_buf))) { + syn_id = check_keyword_id(line, (int)current_col, &endcol, &flags, + &next_list, cur_si, &cchar); if (syn_id != 0) { push_current_state(KEYWORD_IDX); { diff --git a/src/nvim/window.c b/src/nvim/window.c index 07953212c5..9515b88248 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5130,13 +5130,14 @@ file_name_in_line ( * Go one char back to ":" before "//" even when ':' is not in 'isfname'. */ while (ptr > line) { - if ((len = (size_t)(utf_head_off(line, ptr - 1))) > 0) + if ((len = (size_t)(utf_head_off(line, ptr - 1))) > 0) { ptr -= len + 1; - else if (vim_isfilec(ptr[-1]) - || ((options & FNAME_HYP) && path_is_url((char *)ptr - 1))) - --ptr; - else + } else if (vim_isfilec(ptr[-1]) + || ((options & FNAME_HYP) && path_is_url((char *)ptr - 1))) { + ptr--; + } else { break; + } } /* -- cgit