From 10b6afd652a896144d87fb0db4389001293e7973 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Fri, 29 Jun 2018 22:31:20 +0300 Subject: Remove all occurences of the mb_ptr2char macro First step towards implemening issue #7401. The same can be done for all deprecated mb_ functions in follow-up patches. --- src/nvim/buffer.c | 2 +- src/nvim/charset.c | 2 +- src/nvim/cursor.c | 2 +- src/nvim/digraph.c | 2 +- src/nvim/edit.c | 12 ++++++------ src/nvim/eval.c | 2 +- src/nvim/ex_cmds.c | 2 +- src/nvim/ex_docmd.c | 4 ++-- src/nvim/ex_getln.c | 6 +++--- src/nvim/fold.c | 2 +- src/nvim/getchar.c | 4 ++-- src/nvim/macros.h | 2 +- src/nvim/mark.c | 2 +- src/nvim/mbyte.c | 6 +++--- src/nvim/mbyte.h | 1 - src/nvim/message.c | 8 ++++---- src/nvim/misc1.c | 6 +++--- src/nvim/ops.c | 8 ++++---- src/nvim/option.c | 20 ++++++++++---------- src/nvim/regexp.c | 26 +++++++++++++------------- src/nvim/regexp_nfa.c | 4 ++-- src/nvim/spell.c | 52 +++++++++++++++++++++++++-------------------------- src/nvim/syntax.c | 2 +- src/nvim/window.c | 2 +- 24 files changed, 89 insertions(+), 90 deletions(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 3020c29709..67e4b00705 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3223,7 +3223,7 @@ int build_stl_str_hl( if (wp->w_cursor.col > (colnr_T)STRLEN(line_ptr)) byteval = 0; else - byteval = (*mb_ptr2char)(line_ptr + wp->w_cursor.col); + byteval = utf_ptr2char(line_ptr + wp->w_cursor.col); int groupdepth = 0; diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 231bff26e8..f1b3be6b46 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1379,7 +1379,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); if (pos->col < (colnr_T)STRLEN(ptr)) { - int c = (*mb_ptr2char)(ptr + pos->col); + int c = utf_ptr2char(ptr + pos->col); if ((c != TAB) && vim_isprintc(c)) { endadd = (colnr_T)(char2cells(c) - 1); if (coladd > endadd) { diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 177f167d74..abe951dcf5 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -477,7 +477,7 @@ bool leftcol_changed(void) int gchar_cursor(void) { if (has_mbyte) - return (*mb_ptr2char)(get_cursor_pos_ptr()); + return utf_ptr2char(get_cursor_pos_ptr()); return (int)*get_cursor_pos_ptr(); } diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 218a3f0604..c0915224e5 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1536,7 +1536,7 @@ static int getexactdigraph(int char1, int char2, int meta_char) to = string_convert(&vc, buf, &len); if (to != NULL) { - retval = (*mb_ptr2char)(to); + retval = utf_ptr2char(to); xfree(to); } (void)convert_setup(&vc, NULL, NULL); diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 95c903c90c..2cf754698b 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2312,8 +2312,8 @@ static void ins_compl_longest_match(compl_T *match) s = match->cp_str; while (*p != NUL) { if (has_mbyte) { - c1 = mb_ptr2char(p); - c2 = mb_ptr2char(s); + c1 = utf_ptr2char(p); + c2 = utf_ptr2char(s); } else { c1 = *p; c2 = *s; @@ -6199,8 +6199,8 @@ int oneright(void) /* Adjust for multi-wide char (excluding TAB) */ ptr = get_cursor_pos_ptr(); coladvance(getviscol() + ((*ptr != TAB && vim_isprintc( - (*mb_ptr2char)(ptr) - )) + utf_ptr2char(ptr) + )) ? ptr2cells(ptr) : 1)); curwin->w_set_curswant = TRUE; /* Return OK if the cursor moved, FAIL otherwise (at window edge). */ @@ -6259,7 +6259,7 @@ int oneleft(void) /* Adjust for multi-wide char (not a TAB) */ ptr = get_cursor_pos_ptr(); if (*ptr != TAB && vim_isprintc( - (*mb_ptr2char)(ptr) + utf_ptr2char(ptr) ) && ptr2cells(ptr) > 1) curwin->w_cursor.coladd = 0; } @@ -8496,7 +8496,7 @@ int ins_copychar(linenr_T lnum) if ((colnr_T)temp > curwin->w_virtcol) ptr = prev_ptr; - c = (*mb_ptr2char)(ptr); + c = utf_ptr2char(ptr); if (c == NUL) { vim_beep(BO_COPY); } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 3abc39e7bf..ca3c650466 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -15896,7 +15896,7 @@ static void f_strgetchar(typval_T *argvars, typval_T *rettv, FunPtr fptr) while (charidx >= 0 && byteidx < len) { if (charidx == 0) { - rettv->vval.v_number = mb_ptr2char((const char_u *)str + byteidx); + rettv->vval.v_number = utf_ptr2char((const char_u *)str + byteidx); break; } charidx--; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 4ef51b72b7..e99de1ad41 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -5641,7 +5641,7 @@ void ex_sign(exarg_T *eap) // Count cells and check for non-printable chars cells = 0; for (s = arg; s < p; s += (*mb_ptr2len)(s)) { - if (!vim_isprintc((*mb_ptr2char)(s))) { + if (!vim_isprintc(utf_ptr2char(s))) { break; } cells += (*mb_ptr2cells)(s); diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 0ab0178d24..0ff0b1b574 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2900,7 +2900,7 @@ const char * set_one_cmd_context( p = (const char *)xp->xp_pattern; while (*p != NUL) { if (has_mbyte) { - c = mb_ptr2char((const char_u *)p); + c = utf_ptr2char((const char_u *)p); } else { c = (uint8_t)(*p); } @@ -2922,7 +2922,7 @@ const char * set_one_cmd_context( len = 0; /* avoid getting stuck when space is in 'isfname' */ while (*p != NUL) { if (has_mbyte) { - c = mb_ptr2char((const char_u *)p); + c = utf_ptr2char((const char_u *)p); } else { c = *p; } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index ee616ae955..1d1fd866cf 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3329,7 +3329,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) { if (has_mbyte) { len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; - if (!vim_iswordc(mb_ptr2char(w - len))) + if (!vim_iswordc(utf_ptr2char(w - len))) break; w -= len; } else { @@ -3845,13 +3845,13 @@ ExpandOne ( for (len = 0; xp->xp_files[0][len]; len += mb_len) { if (has_mbyte) { mb_len = (* mb_ptr2len)(&xp->xp_files[0][len]); - c0 = (* mb_ptr2char)(&xp->xp_files[0][len]); + c0 = utf_ptr2char(&xp->xp_files[0][len]); } else { c0 = xp->xp_files[0][len]; } for (i = 1; i < xp->xp_numfiles; ++i) { if (has_mbyte) { - ci =(* mb_ptr2char)(&xp->xp_files[i][len]); + ci = utf_ptr2char(&xp->xp_files[i][len]); } else { ci = xp->xp_files[i][len]; } diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 1ed34ef124..53fb63b726 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1767,7 +1767,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, int len; if (has_mbyte && (len = (*mb_ptr2len)(p)) > 1) { - if (!vim_isprintc((*mb_ptr2char)(p))) + if (!vim_isprintc(utf_ptr2char(p))) break; p += len - 1; } else if (*p == TAB) diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index e20c75cf7b..b57e1f6558 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -701,7 +701,7 @@ static int read_redo(int init, int old_redo) buf[i] = (char_u)c; if (i == n - 1) { // last byte of a character if (n != 1) { - c = (*mb_ptr2char)(buf); + c = utf_ptr2char(buf); } break; } @@ -1486,7 +1486,7 @@ int vgetc(void) } } no_mapping--; - c = (*mb_ptr2char)(buf); + c = utf_ptr2char(buf); } break; diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 7eb58bea2a..b02af723b4 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -126,7 +126,7 @@ # define MB_CHARLEN(p) mb_charlen(p) # define MB_CHAR2LEN(c) mb_char2len(c) -# define PTR2CHAR(p) mb_ptr2char(p) +# define PTR2CHAR(p) utf_ptr2char(p) # define RESET_BINDING(wp) (wp)->w_p_scb = FALSE; (wp)->w_p_crb = FALSE diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 49e60b5166..b9c91de2a8 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -1470,7 +1470,7 @@ void mark_mb_adjustpos(buf_T *buf, pos_T *lp) // double-wide character. if (lp->coladd == 1 && p[lp->col] != TAB - && vim_isprintc((*mb_ptr2char)(p + lp->col)) + && vim_isprintc(utf_ptr2char(p + lp->col)) && ptr2cells(p + lp->col) > 1) { lp->coladd = 0; } diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 65a1a8246c..7c196831ba 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -674,7 +674,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 +687,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; } @@ -1714,7 +1714,7 @@ void mb_check_adjust_col(void *win_) // 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; } diff --git a/src/nvim/mbyte.h b/src/nvim/mbyte.h index 99aadcacad..a21c08c7fe 100644 --- a/src/nvim/mbyte.h +++ b/src/nvim/mbyte.h @@ -54,7 +54,6 @@ enum { MAX_MCO = 6 }; #define mb_ptr2cells_len utf_ptr2cells_len #define mb_char2cells utf_char2cells #define mb_off2cells utf_off2cells -#define mb_ptr2char utf_ptr2char #define mb_head_off utf_head_off /// Flags for vimconv_T diff --git a/src/nvim/message.c b/src/nvim/message.c index 46fc9115b4..d285086cc5 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1219,7 +1219,7 @@ int msg_outtrans_len_attr(char_u *msgstr, int len, int attr) // Don't include composing chars after the end. mb_l = utfc_ptr2len_len((char_u *)str, len + 1); if (mb_l > 1) { - c = (*mb_ptr2char)((char_u *)str); + c = utf_ptr2char((char_u *)str); if (vim_isprintc(c)) { // Printable multi-byte char: count the cells. retval += (*mb_ptr2cells)((char_u *)str); @@ -1480,7 +1480,7 @@ void msg_prt_line(char_u *s, int list) col += (*mb_ptr2cells)(s); char buf[MB_MAXBYTES + 1]; if (lcs_nbsp != NUL && list - && (mb_ptr2char(s) == 160 || mb_ptr2char(s) == 0x202f)) { + && (utf_ptr2char(s) == 160 || utf_ptr2char(s) == 0x202f)) { mb_char2bytes(lcs_nbsp, (char_u *)buf); buf[(*mb_ptr2len)((char_u *)buf)] = NUL; } else { @@ -2868,7 +2868,7 @@ do_dialog ( retval = 1; for (i = 0; hotkeys[i]; ++i) { if (has_mbyte) { - if ((*mb_ptr2char)(hotkeys + i) == c) + if (utf_ptr2char(hotkeys + i) == c) break; i += (*mb_ptr2len)(hotkeys + i) - 1; } else if (hotkeys[i] == c) @@ -2910,7 +2910,7 @@ copy_char ( if (has_mbyte) { if (lowercase) { - c = mb_tolower((*mb_ptr2char)(from)); + c = mb_tolower(utf_ptr2char(from)); return (*mb_char2bytes)(c, to); } else { len = (*mb_ptr2len)(from); diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index d2ecb9a74b..3a87d0a4d1 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -1512,7 +1512,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) && msg_silent == 0 && !ins_compl_active() ) { - showmatch(mb_ptr2char(buf)); + showmatch(utf_ptr2char(buf)); } if (!p_ri || (State & REPLACE_FLAG)) { @@ -1752,7 +1752,7 @@ int gchar_pos(pos_T *pos) char_u *ptr = ml_get_pos(pos); if (has_mbyte) - return (*mb_ptr2char)(ptr); + return utf_ptr2char(ptr); return (int)*ptr; } @@ -2393,7 +2393,7 @@ int get_keystroke(void) if (MB_BYTE2LEN(n) > len) continue; /* more bytes to get */ buf[len >= buflen ? buflen - 1 : len] = NUL; - n = (*mb_ptr2char)(buf); + n = utf_ptr2char(buf); } #ifdef UNIX if (n == intr_char) diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 4fb1a1ea9d..05955f4215 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3620,9 +3620,9 @@ int do_join(size_t count, curr = skipwhite(curr); if (*curr != ')' && currsize != 0 && endcurr1 != TAB && (!has_format_option(FO_MBYTE_JOIN) - || (mb_ptr2char(curr) < 0x100 && endcurr1 < 0x100)) + || (utf_ptr2char(curr) < 0x100 && endcurr1 < 0x100)) && (!has_format_option(FO_MBYTE_JOIN2) - || mb_ptr2char(curr) < 0x100 || endcurr1 < 0x100) + || utf_ptr2char(curr) < 0x100 || endcurr1 < 0x100) ) { /* don't add a space if the line is ending in a space */ if (endcurr1 == ' ') @@ -3642,10 +3642,10 @@ int do_join(size_t count, if (has_mbyte) { cend = curr + currsize; MB_PTR_BACK(curr, cend); - endcurr1 = (*mb_ptr2char)(cend); + endcurr1 = utf_ptr2char(cend); if (cend > curr) { MB_PTR_BACK(curr, cend); - endcurr2 = (*mb_ptr2char)(cend); + endcurr2 = utf_ptr2char(cend); } } else { endcurr1 = *(curr + currsize - 1); diff --git a/src/nvim/option.c b/src/nvim/option.c index 50c172b580..1ee6e18227 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2703,7 +2703,7 @@ did_set_string_option ( if (*p != NUL) x2 = *p++; if (*p != NUL) { - x3 = mb_ptr2char(p); + x3 = utf_ptr2char(p); p += mb_ptr2len(p); } if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) { @@ -6408,20 +6408,20 @@ static void langmap_set(void) } if (p[0] == '\\' && p[1] != NUL) ++p; - from = (*mb_ptr2char)(p); + from = utf_ptr2char(p); to = NUL; if (p2 == NULL) { MB_PTR_ADV(p); if (p[0] != ',') { if (p[0] == '\\') ++p; - to = (*mb_ptr2char)(p); + to = utf_ptr2char(p); } } else { if (p2[0] != ',') { if (p2[0] == '\\') ++p2; - to = (*mb_ptr2char)(p2); + to = utf_ptr2char(p2); } } if (to == NUL) { @@ -6853,26 +6853,26 @@ void find_mps_values(int *initc, int *findc, int *backwards, int switchit) if (has_mbyte) { char_u *prev; - if (mb_ptr2char(ptr) == *initc) { + if (utf_ptr2char(ptr) == *initc) { if (switchit) { *findc = *initc; - *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1); + *initc = utf_ptr2char(ptr + mb_ptr2len(ptr) + 1); *backwards = TRUE; } else { - *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1); + *findc = utf_ptr2char(ptr + mb_ptr2len(ptr) + 1); *backwards = FALSE; } return; } prev = ptr; ptr += mb_ptr2len(ptr) + 1; - if (mb_ptr2char(ptr) == *initc) { + if (utf_ptr2char(ptr) == *initc) { if (switchit) { *findc = *initc; - *initc = mb_ptr2char(prev); + *initc = utf_ptr2char(prev); *backwards = FALSE; } else { - *findc = mb_ptr2char(prev); + *findc = utf_ptr2char(prev); *backwards = TRUE; } return; diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index d76da62c6d..ca4db722ad 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -776,7 +776,7 @@ static int get_equi_class(char_u **pp) l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '=' && p[l + 3] == ']') { if (has_mbyte) - c = mb_ptr2char(p + 2); + c = utf_ptr2char(p + 2); else c = p[2]; *pp += l + 4; @@ -1111,7 +1111,7 @@ static int get_coll_element(char_u **pp) l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '.' && p[l + 3] == ']') { if (has_mbyte) - c = mb_ptr2char(p + 2); + c = utf_ptr2char(p + 2); else c = p[2]; *pp += l + 4; @@ -1300,7 +1300,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) if (OP(scan) == EXACTLY) { if (has_mbyte) - r->regstart = (*mb_ptr2char)(OPERAND(scan)); + r->regstart = utf_ptr2char(OPERAND(scan)); else r->regstart = *OPERAND(scan); } else if (OP(scan) == BOW @@ -1311,7 +1311,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) char_u *regnext_scan = regnext(scan); if (OP(regnext_scan) == EXACTLY) { if (has_mbyte) - r->regstart = (*mb_ptr2char)(OPERAND(regnext_scan)); + r->regstart = utf_ptr2char(OPERAND(regnext_scan)); else r->regstart = *OPERAND(regnext_scan); } @@ -2417,7 +2417,7 @@ collection: /* produce a multibyte character, including any * following composing characters */ - startc = mb_ptr2char(regparse); + startc = utf_ptr2char(regparse); len = (*mb_ptr2len)(regparse); if (enc_utf8 && utf_char2len(startc) != len) startc = -1; /* composing chars */ @@ -2907,7 +2907,7 @@ static int peekchr(void) * Then backslashing it won't do anything. */ if (has_mbyte) - curchr = (*mb_ptr2char)(regparse + 1); + curchr = utf_ptr2char(regparse + 1); else curchr = c; } @@ -2916,7 +2916,7 @@ static int peekchr(void) default: if (has_mbyte) - curchr = (*mb_ptr2char)(regparse); + curchr = utf_ptr2char(regparse); } return curchr; @@ -3469,7 +3469,7 @@ static long bt_regexec_both(char_u *line, int c; if (has_mbyte) - c = (*mb_ptr2char)(prog->regmust); + c = utf_ptr2char(prog->regmust); else c = *prog->regmust; s = line + col; @@ -3505,7 +3505,7 @@ static long bt_regexec_both(char_u *line, int c; if (has_mbyte) - c = (*mb_ptr2char)(regline + col); + c = utf_ptr2char(regline + col); else c = regline[col]; if (prog->regstart == NUL @@ -3861,7 +3861,7 @@ regmatch ( if (WITH_NL(op)) op -= ADD_NL; if (has_mbyte) - c = (*mb_ptr2char)(reginput); + c = utf_ptr2char(reginput); else c = *reginput; switch (op) { @@ -5474,7 +5474,7 @@ do_class: } else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) { scan++; } else if (has_mbyte && (len = (*mb_ptr2len)(scan)) > 1) { - if ((cstrchr(opnd, (*mb_ptr2char)(scan)) == NULL) == testval) { + if ((cstrchr(opnd, utf_ptr2char(scan)) == NULL) == testval) { break; } scan += len; @@ -6783,7 +6783,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, c = *src++; } } else if (has_mbyte) - c = mb_ptr2char(src - 1); + c = utf_ptr2char(src - 1); /* Write to buffer, if copy is set. */ if (func_one != (fptr_T)NULL) @@ -6879,7 +6879,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, dst += 2; } else { if (has_mbyte) - c = mb_ptr2char(s); + c = utf_ptr2char(s); else c = *s; diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 2eb0ca9313..1a44a6119e 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -5034,7 +5034,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, int clen; if (has_mbyte) { - curc = (*mb_ptr2char)(reginput); + curc = utf_ptr2char(reginput); clen = (*mb_ptr2len)(reginput); } else { curc = *reginput; @@ -5501,7 +5501,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, // We don't care about the order of composing characters. // Get them into cchars[] first. while (len < clen) { - mc = mb_ptr2char(reginput + len); + mc = utf_ptr2char(reginput + len); cchars[ccount++] = mc; len += mb_char2len(mc); if (ccount == MAX_MCO) diff --git a/src/nvim/spell.c b/src/nvim/spell.c index cb03257878..8282cfa378 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1956,7 +1956,7 @@ static int count_syllables(slang_T *slang, char_u *word) skip = false; } else { // No recognized syllable item, at least a syllable char then? - c = mb_ptr2char(p); + c = utf_ptr2char(p); len = (*mb_ptr2len)(p); if (vim_strchr(slang->sl_syllable, c) == NULL) skip = false; // No, search for next syllable @@ -2271,7 +2271,7 @@ static void use_midword(slang_T *lp, win_T *wp) int c, l, n; char_u *bp; - c = mb_ptr2char(p); + c = utf_ptr2char(p); l = (*mb_ptr2len)(p); if (c < 256 && l <= 2) wp->w_s->b_spell_ismw[c] = true; @@ -2597,14 +2597,14 @@ static bool spell_iswordp(char_u *p, win_T *wp) if (wp->w_s->b_spell_ismw[*p]) s = p + 1; // skip a mid-word character } else { - c = mb_ptr2char(p); + c = utf_ptr2char(p); if (c < 256 ? wp->w_s->b_spell_ismw[c] : (wp->w_s->b_spell_ismw_mb != NULL && vim_strchr(wp->w_s->b_spell_ismw_mb, c) != NULL)) s = p + l; } - c = mb_ptr2char(s); + c = utf_ptr2char(s); if (c > 255) return spell_mb_isword_class(mb_get_class(s), wp); return spelltab.st_isw[c]; @@ -2620,7 +2620,7 @@ bool spell_iswordp_nmw(const char_u *p, win_T *wp) int c; if (has_mbyte) { - c = mb_ptr2char(p); + c = utf_ptr2char(p); if (c > 255) { return spell_mb_isword_class(mb_get_class(p), wp); } @@ -4303,10 +4303,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so } else if (!soundfold && slang->sl_has_map && similar_chars(slang, - mb_ptr2char(tword + utf_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen), - mb_ptr2char(fword + utf_ptr2char(fword + sp->ts_fcharstart))) { // For a similar character adjust score from // SCORE_SUBST to SCORE_SIMILAR. @@ -4315,7 +4315,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so } else if (sp->ts_isdiff == DIFF_INSERT && sp->ts_twordlen > sp->ts_tcharlen) { p = tword + sp->ts_twordlen - sp->ts_tcharlen; - c = mb_ptr2char(p); + c = utf_ptr2char(p); if (enc_utf8 && utf_iscomposing(c)) { // Inserting a composing char doesn't // count that much. @@ -4327,7 +4327,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // tree (might seem illogical but does // give better scores). MB_PTR_BACK(tword, p); - if (c == mb_ptr2char(p)) { + if (c == utf_ptr2char(p)) { sp->ts_score -= SCORE_INS - SCORE_INSDUP; } } @@ -4389,11 +4389,11 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // a bit illogical for soundfold tree but it does give better // results. if (has_mbyte) { - c = mb_ptr2char(fword + sp->ts_fidx); + c = utf_ptr2char(fword + sp->ts_fidx); stack[depth].ts_fidx += MB_PTR2LEN(fword + sp->ts_fidx); if (enc_utf8 && utf_iscomposing(c)) { stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; - } else if (c == mb_ptr2char(fword + stack[depth].ts_fidx)) { + } else if (c == utf_ptr2char(fword + stack[depth].ts_fidx)) { stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; } } else { @@ -4517,13 +4517,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (has_mbyte) { n = MB_CPTR2LEN(p); - c = mb_ptr2char(p); + c = utf_ptr2char(p); if (p[n] == NUL) c2 = NUL; else if (!soundfold && !spell_iswordp(p + n, curwin)) c2 = c; // don't swap non-word char else - c2 = mb_ptr2char(p + n); + c2 = utf_ptr2char(p + n); } else { if (p[1] == NUL) c2 = NUL; @@ -4578,7 +4578,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so p = fword + sp->ts_fidx; if (has_mbyte) { n = MB_PTR2LEN(p); - c = mb_ptr2char(p + n); + c = utf_ptr2char(p + n); memmove(p + MB_PTR2LEN(p + n), p, n); mb_char2bytes(c, p); } else { @@ -4594,13 +4594,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so p = fword + sp->ts_fidx; if (has_mbyte) { n = MB_CPTR2LEN(p); - c = mb_ptr2char(p); + c = utf_ptr2char(p); fl = MB_CPTR2LEN(p + n); - c2 = mb_ptr2char(p + n); + c2 = utf_ptr2char(p + n); if (!soundfold && !spell_iswordp(p + n + fl, curwin)) c3 = c; // don't swap non-word char else - c3 = mb_ptr2char(p + n + fl); + c3 = utf_ptr2char(p + n + fl); } else { c = *p; c2 = p[1]; @@ -4653,9 +4653,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so p = fword + sp->ts_fidx; if (has_mbyte) { n = MB_PTR2LEN(p); - c2 = mb_ptr2char(p + n); + c2 = utf_ptr2char(p + n); fl = MB_PTR2LEN(p + n); - c = mb_ptr2char(p + n + fl); + c = utf_ptr2char(p + n + fl); tl = MB_PTR2LEN(p + n + fl); memmove(p + fl + tl, p, n); mb_char2bytes(c, p); @@ -4692,7 +4692,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so p = fword + sp->ts_fidx; if (has_mbyte) { n = MB_CPTR2LEN(p); - c = mb_ptr2char(p); + c = utf_ptr2char(p); fl = MB_CPTR2LEN(p + n); fl += MB_CPTR2LEN(p + n + fl); memmove(p, p + n, fl); @@ -4717,7 +4717,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (has_mbyte) { n = MB_PTR2LEN(p); n += MB_PTR2LEN(p + n); - c = mb_ptr2char(p + n); + c = utf_ptr2char(p + n); tl = MB_PTR2LEN(p + n); memmove(p + tl, p, n); mb_char2bytes(c, p); @@ -4745,7 +4745,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (has_mbyte) { n = MB_CPTR2LEN(p); n += MB_CPTR2LEN(p + n); - c = mb_ptr2char(p + n); + c = utf_ptr2char(p + n); tl = MB_CPTR2LEN(p + n); memmove(p + tl, p, n); mb_char2bytes(c, p); @@ -4767,7 +4767,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Undo ROT3R: "312" -> "123" p = fword + sp->ts_fidx; if (has_mbyte) { - c = mb_ptr2char(p); + c = utf_ptr2char(p); tl = MB_PTR2LEN(p); n = MB_PTR2LEN(p + tl); n += MB_PTR2LEN(p + tl + n); @@ -5607,7 +5607,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2) if (HASHITEM_EMPTY(hi)) m1 = 0; else - m1 = mb_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1); + m1 = utf_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1); } else m1 = slang->sl_map_array[c1]; if (m1 == 0) @@ -5620,7 +5620,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2) if (HASHITEM_EMPTY(hi)) m2 = 0; else - m2 = mb_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1); + m2 = utf_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1); } else m2 = slang->sl_map_array[c2]; @@ -5660,7 +5660,7 @@ add_suggestion ( MB_PTR_BACK(goodword, pgood); MB_PTR_BACK(su->su_badptr, pbad); if (has_mbyte) { - if (mb_ptr2char(pgood) != mb_ptr2char(pbad)) + if (utf_ptr2char(pgood) != utf_ptr2char(pbad)) break; } else if (*pgood != *pbad) break; diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index bd590f53c0..2f142e65c9 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4103,7 +4103,7 @@ get_syn_options( } else if (flagtab[fidx].argtype == 11 && arg[5] == '=') { /* cchar=? */ if (has_mbyte) { - *conceal_char = mb_ptr2char(arg + 6); + *conceal_char = utf_ptr2char(arg + 6); arg += mb_ptr2len(arg + 6) - 1; } else { *conceal_char = arg[6]; diff --git a/src/nvim/window.c b/src/nvim/window.c index 7582c837c8..9286894e08 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5609,7 +5609,7 @@ int match_add(win_T *wp, const char *const grp, const char *const pat, m->match.rmm_maxcol = 0; m->conceal_char = 0; if (conceal_char != NULL) { - m->conceal_char = (*mb_ptr2char)((const char_u *)conceal_char); + m->conceal_char = utf_ptr2char((const char_u *)conceal_char); } // Set up position matches -- cgit From cd3b2e4b6bea9501b3bd7ddf7b4d7ca31f1e6dd5 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Sat, 30 Jun 2018 13:29:09 +0300 Subject: lint: clean-up after parent commit --- src/nvim/buffer.c | 5 +-- src/nvim/cursor.c | 6 ++-- src/nvim/edit.c | 16 +++++----- src/nvim/ex_getln.c | 3 +- src/nvim/fold.c | 3 +- src/nvim/message.c | 3 +- src/nvim/misc1.c | 8 ++--- src/nvim/option.c | 23 ++++++++------ src/nvim/regexp.c | 51 ++++++++++++++++++------------ src/nvim/spell.c | 89 +++++++++++++++++++++++++++++------------------------ 10 files changed, 115 insertions(+), 92 deletions(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 67e4b00705..71e04ec0fb 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3220,10 +3220,11 @@ int build_stl_str_hl( // Get the byte value now, in case we need it below. This is more // efficient than making a copy of the line. int byteval; - if (wp->w_cursor.col > (colnr_T)STRLEN(line_ptr)) + if (wp->w_cursor.col > (colnr_T)STRLEN(line_ptr)) { byteval = 0; - else + } else { byteval = utf_ptr2char(line_ptr + wp->w_cursor.col); + } int groupdepth = 0; diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index abe951dcf5..a7f2f5a247 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -476,9 +476,10 @@ bool leftcol_changed(void) int gchar_cursor(void) { - if (has_mbyte) + if (has_mbyte) { return utf_ptr2char(get_cursor_pos_ptr()); - return (int)*get_cursor_pos_ptr(); + } + return (int)(*get_cursor_pos_ptr()); } /* @@ -507,4 +508,3 @@ char_u *get_cursor_pos_ptr(void) return ml_get_buf(curbuf, curwin->w_cursor.lnum, false) + curwin->w_cursor.col; } - diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 2cf754698b..281f26c9df 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -6198,12 +6198,10 @@ int oneright(void) /* Adjust for multi-wide char (excluding TAB) */ ptr = get_cursor_pos_ptr(); - coladvance(getviscol() + ((*ptr != TAB && vim_isprintc( - utf_ptr2char(ptr) - )) - ? ptr2cells(ptr) : 1)); - curwin->w_set_curswant = TRUE; - /* Return OK if the cursor moved, FAIL otherwise (at window edge). */ + coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(utf_ptr2char(ptr))) ? + ptr2cells(ptr) : 1)); + curwin->w_set_curswant = true; + // Return OK if the cursor moved, FAIL otherwise (at window edge). return (prevpos.col != curwin->w_cursor.col || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL; } @@ -6258,10 +6256,10 @@ int oneleft(void) /* Adjust for multi-wide char (not a TAB) */ ptr = get_cursor_pos_ptr(); - if (*ptr != TAB && vim_isprintc( - utf_ptr2char(ptr) - ) && ptr2cells(ptr) > 1) + if (*ptr != TAB && vim_isprintc(utf_ptr2char(ptr)) + && ptr2cells(ptr) > 1) { curwin->w_cursor.coladd = 0; + } } curwin->w_set_curswant = TRUE; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 1d1fd866cf..52f4f3bde4 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3329,8 +3329,9 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) { if (has_mbyte) { len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; - if (!vim_iswordc(utf_ptr2char(w - len))) + if (!vim_iswordc(utf_ptr2char(w - len))) { break; + } w -= len; } else { if (!vim_iswordc(w[-1])) diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 53fb63b726..2781643a5d 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1767,8 +1767,9 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, int len; if (has_mbyte && (len = (*mb_ptr2len)(p)) > 1) { - if (!vim_isprintc(utf_ptr2char(p))) + if (!vim_isprintc(utf_ptr2char(p))) { break; + } p += len - 1; } else if (*p == TAB) *p = ' '; diff --git a/src/nvim/message.c b/src/nvim/message.c index d285086cc5..ddbc17439b 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -2868,8 +2868,9 @@ do_dialog ( retval = 1; for (i = 0; hotkeys[i]; ++i) { if (has_mbyte) { - if (utf_ptr2char(hotkeys + i) == c) + if (utf_ptr2char(hotkeys + i) == c) { break; + } i += (*mb_ptr2len)(hotkeys + i) - 1; } else if (hotkeys[i] == c) break; diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 3a87d0a4d1..01f9cb9e32 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -1749,11 +1749,12 @@ del_lines ( int gchar_pos(pos_T *pos) { - char_u *ptr = ml_get_pos(pos); + char_u *ptr = ml_get_pos(pos); - if (has_mbyte) + if (has_mbyte) { return utf_ptr2char(ptr); - return (int)*ptr; + } + return (int)(*ptr); } /* @@ -2840,4 +2841,3 @@ int goto_im(void) { return p_im && stuff_empty() && typebuf_typed(); } - diff --git a/src/nvim/option.c b/src/nvim/option.c index 1ee6e18227..c06485c63e 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -6406,21 +6406,24 @@ static void langmap_set(void) ++p; break; } - if (p[0] == '\\' && p[1] != NUL) - ++p; + if (p[0] == '\\' && p[1] != NUL) { + p++; + } from = utf_ptr2char(p); to = NUL; if (p2 == NULL) { MB_PTR_ADV(p); if (p[0] != ',') { - if (p[0] == '\\') - ++p; + if (p[0] == '\\') { + p++; + } to = utf_ptr2char(p); } } else { if (p2[0] != ',') { - if (p2[0] == '\\') - ++p2; + if (p2[0] == '\\') { + p2++; + } to = utf_ptr2char(p2); } } @@ -6857,10 +6860,10 @@ void find_mps_values(int *initc, int *findc, int *backwards, int switchit) if (switchit) { *findc = *initc; *initc = utf_ptr2char(ptr + mb_ptr2len(ptr) + 1); - *backwards = TRUE; + *backwards = true; } else { *findc = utf_ptr2char(ptr + mb_ptr2len(ptr) + 1); - *backwards = FALSE; + *backwards = false; } return; } @@ -6870,10 +6873,10 @@ void find_mps_values(int *initc, int *findc, int *backwards, int switchit) if (switchit) { *findc = *initc; *initc = utf_ptr2char(prev); - *backwards = FALSE; + *backwards = false; } else { *findc = utf_ptr2char(prev); - *backwards = TRUE; + *backwards = true; } return; } diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index ca4db722ad..1b711bd881 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -775,10 +775,11 @@ static int get_equi_class(char_u **pp) if (has_mbyte) l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '=' && p[l + 3] == ']') { - if (has_mbyte) + if (has_mbyte) { c = utf_ptr2char(p + 2); - else + } else { c = p[2]; + } *pp += l + 4; return c; } @@ -1110,10 +1111,11 @@ static int get_coll_element(char_u **pp) if (has_mbyte) l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '.' && p[l + 3] == ']') { - if (has_mbyte) + if (has_mbyte) { c = utf_ptr2char(p + 2); - else + } else { c = p[2]; + } *pp += l + 4; return c; } @@ -1299,10 +1301,11 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) } if (OP(scan) == EXACTLY) { - if (has_mbyte) + if (has_mbyte) { r->regstart = utf_ptr2char(OPERAND(scan)); - else + } else { r->regstart = *OPERAND(scan); + } } else if (OP(scan) == BOW || OP(scan) == EOW || OP(scan) == NOTHING @@ -1310,10 +1313,11 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) || OP(scan) == MCLOSE + 0 || OP(scan) == NCLOSE) { char_u *regnext_scan = regnext(scan); if (OP(regnext_scan) == EXACTLY) { - if (has_mbyte) + if (has_mbyte) { r->regstart = utf_ptr2char(OPERAND(regnext_scan)); - else + } else { r->regstart = *OPERAND(regnext_scan); + } } } @@ -2906,17 +2910,19 @@ static int peekchr(void) * Next character can never be (made) magic? * Then backslashing it won't do anything. */ - if (has_mbyte) + if (has_mbyte) { curchr = utf_ptr2char(regparse + 1); - else + } else { curchr = c; + } } break; } default: - if (has_mbyte) + if (has_mbyte) { curchr = utf_ptr2char(regparse); + } } return curchr; @@ -3468,10 +3474,11 @@ static long bt_regexec_both(char_u *line, if (prog->regmust != NULL) { int c; - if (has_mbyte) + if (has_mbyte) { c = utf_ptr2char(prog->regmust); - else + } else { c = *prog->regmust; + } s = line + col; // This is used very often, esp. for ":global". Use two versions of @@ -3504,10 +3511,11 @@ static long bt_regexec_both(char_u *line, if (prog->reganch) { int c; - if (has_mbyte) + if (has_mbyte) { c = utf_ptr2char(regline + col); - else + } else { c = regline[col]; + } if (prog->regstart == NUL || prog->regstart == c || (rex.reg_ic @@ -3860,10 +3868,11 @@ regmatch ( } else { if (WITH_NL(op)) op -= ADD_NL; - if (has_mbyte) + if (has_mbyte) { c = utf_ptr2char(reginput); - else + } else { c = *reginput; + } switch (op) { case BOL: if (reginput != regline) @@ -6782,8 +6791,9 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, } c = *src++; } - } else if (has_mbyte) + } else if (has_mbyte) { c = utf_ptr2char(src - 1); + } /* Write to buffer, if copy is set. */ if (func_one != (fptr_T)NULL) @@ -6878,10 +6888,11 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, } dst += 2; } else { - if (has_mbyte) + if (has_mbyte) { c = utf_ptr2char(s); - else + } else { c = *s; + } if (func_one != (fptr_T)NULL) /* Turbo C complains without the typecast */ diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 8282cfa378..3d393acadb 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2600,13 +2600,15 @@ static bool spell_iswordp(char_u *p, win_T *wp) c = utf_ptr2char(p); if (c < 256 ? wp->w_s->b_spell_ismw[c] : (wp->w_s->b_spell_ismw_mb != NULL - && vim_strchr(wp->w_s->b_spell_ismw_mb, c) != NULL)) + && vim_strchr(wp->w_s->b_spell_ismw_mb, c) != NULL)) { s = p + l; + } } c = utf_ptr2char(s); - if (c > 255) + if (c > 255) { return spell_mb_isword_class(mb_get_class(s), wp); + } return spelltab.st_isw[c]; } @@ -4300,14 +4302,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so && utf_iscomposing(utf_ptr2char(fword + sp->ts_fcharstart))) { sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP; - } else if (!soundfold - && slang->sl_has_map + } else if (!soundfold && slang->sl_has_map && similar_chars(slang, - utf_ptr2char(tword - + sp->ts_twordlen - - sp->ts_tcharlen), - utf_ptr2char(fword - + sp->ts_fcharstart))) { + utf_ptr2char(tword + sp->ts_twordlen + - sp->ts_tcharlen), + utf_ptr2char(fword + + sp->ts_fcharstart))) { // For a similar character adjust score from // SCORE_SUBST to SCORE_SIMILAR. sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR; @@ -4518,19 +4518,21 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (has_mbyte) { n = MB_CPTR2LEN(p); c = utf_ptr2char(p); - if (p[n] == NUL) + if (p[n] == NUL) { c2 = NUL; - else if (!soundfold && !spell_iswordp(p + n, curwin)) - c2 = c; // don't swap non-word char - else + } else if (!soundfold && !spell_iswordp(p + n, curwin)) { + c2 = c; // don't swap non-word char + } else { c2 = utf_ptr2char(p + n); + } } else { - if (p[1] == NUL) + if (p[1] == NUL) { c2 = NUL; - else if (!soundfold && !spell_iswordp(p + 1, curwin)) - c2 = c; // don't swap non-word char - else + } else if (!soundfold && !spell_iswordp(p + 1, curwin)) { + c2 = c; // don't swap non-word char + } else { c2 = p[1]; + } } // When the second character is NUL we can't swap. @@ -4538,17 +4540,17 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; break; - } + } - // When characters are identical, swap won't do anything. - // Also get here if the second char is not a word character. - if (c == c2) { - PROF_STORE(sp->ts_state) - sp->ts_state = STATE_SWAP3; - break; - } - if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP)) { - go_deeper(stack, depth, SCORE_SWAP); + // When characters are identical, swap won't do anything. + // Also get here if the second char is not a word character. + if (c == c2) { + PROF_STORE(sp->ts_state) + sp->ts_state = STATE_SWAP3; + break; + } + if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP)) { + go_deeper(stack, depth, SCORE_SWAP); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "%.*s-%s: swap %c and %c", sp->ts_twordlen, tword, fword + sp->ts_fidx, @@ -4597,10 +4599,11 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so c = utf_ptr2char(p); fl = MB_CPTR2LEN(p + n); c2 = utf_ptr2char(p + n); - if (!soundfold && !spell_iswordp(p + n + fl, curwin)) + if (!soundfold && !spell_iswordp(p + n + fl, curwin)) { c3 = c; // don't swap non-word char - else + } else { c3 = utf_ptr2char(p + n + fl); + } } else { c = *p; c2 = p[1]; @@ -5604,25 +5607,29 @@ static bool similar_chars(slang_T *slang, int c1, int c2) if (c1 >= 256) { buf[mb_char2bytes(c1, buf)] = 0; hi = hash_find(&slang->sl_map_hash, buf); - if (HASHITEM_EMPTY(hi)) + if (HASHITEM_EMPTY(hi)) { m1 = 0; - else + } else { m1 = utf_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1); - } else + } + } else { m1 = slang->sl_map_array[c1]; - if (m1 == 0) + } + if (m1 == 0) { return false; - + } if (c2 >= 256) { buf[mb_char2bytes(c2, buf)] = 0; hi = hash_find(&slang->sl_map_hash, buf); - if (HASHITEM_EMPTY(hi)) + if (HASHITEM_EMPTY(hi)) { m2 = 0; - else + } else { m2 = utf_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1); - } else + } + } else { m2 = slang->sl_map_array[c2]; + } return m1 == m2; } @@ -5660,10 +5667,12 @@ add_suggestion ( MB_PTR_BACK(goodword, pgood); MB_PTR_BACK(su->su_badptr, pbad); if (has_mbyte) { - if (utf_ptr2char(pgood) != utf_ptr2char(pbad)) + if (utf_ptr2char(pgood) != utf_ptr2char(pbad)) { break; - } else if (*pgood != *pbad) + } + } else if (*pgood != *pbad) { break; + } } if (badlen == 0 && goodlen == 0) @@ -7608,5 +7617,3 @@ int expand_spelling(linenr_T lnum, char_u *pat, char_u ***matchp) *matchp = ga.ga_data; return ga.ga_len; } - - -- cgit From 071aab51488e03a0e09a0a60aec6c0abc0277279 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Sat, 30 Jun 2018 16:21:37 +0300 Subject: Remove some occrrences of enc_utf8 and has_mbyte Removing uses and related dead code in the locallity of changes of the two parent commits. --- src/nvim/cursor.c | 5 +- src/nvim/edit.c | 22 ++---- src/nvim/misc1.c | 28 +++----- src/nvim/regexp.c | 115 ++++++++++-------------------- src/nvim/regexp_nfa.c | 9 +-- src/nvim/search.c | 4 +- src/nvim/spell.c | 188 ++++++++++++++++---------------------------------- src/nvim/syntax.c | 10 +-- 8 files changed, 121 insertions(+), 260 deletions(-) diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index a7f2f5a247..0fda941a51 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -476,10 +476,7 @@ bool leftcol_changed(void) int gchar_cursor(void) { - if (has_mbyte) { - return utf_ptr2char(get_cursor_pos_ptr()); - } - return (int)(*get_cursor_pos_ptr()); + return utf_ptr2char(get_cursor_pos_ptr()); } /* diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 281f26c9df..b5c702828c 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2311,24 +2311,14 @@ static void ins_compl_longest_match(compl_T *match) p = compl_leader; s = match->cp_str; while (*p != NUL) { - if (has_mbyte) { - c1 = utf_ptr2char(p); - c2 = utf_ptr2char(s); - } else { - c1 = *p; - c2 = *s; - } - if (match->cp_icase ? (mb_tolower(c1) != mb_tolower(c2)) - : (c1 != c2)) { + c1 = utf_ptr2char(p); + c2 = utf_ptr2char(s); + + if (match->cp_icase ? (mb_tolower(c1) != mb_tolower(c2)) : (c1 != c2)) { break; } - if (has_mbyte) { - MB_PTR_ADV(p); - MB_PTR_ADV(s); - } else { - ++p; - ++s; - } + MB_PTR_ADV(p); + MB_PTR_ADV(s); } if (*p != NUL) { diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 01f9cb9e32..72490a376f 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -701,13 +701,12 @@ open_line ( replace_push(NUL); /* end of extra blanks */ if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) { while ((*p_extra == ' ' || *p_extra == '\t') - && (!enc_utf8 - || !utf_iscomposing(utf_ptr2char(p_extra + 1))) - ) { - if (REPLACE_NORMAL(State)) + && !utf_iscomposing(utf_ptr2char(p_extra + 1))) { + if (REPLACE_NORMAL(State)) { replace_push(*p_extra); - ++p_extra; - ++less_cols_off; + } + p_extra++; + less_cols_off++; } } if (*p_extra != NUL) { @@ -1749,12 +1748,7 @@ del_lines ( int gchar_pos(pos_T *pos) { - char_u *ptr = ml_get_pos(pos); - - if (has_mbyte) { - return utf_ptr2char(ptr); - } - return (int)(*ptr); + return utf_ptr2char(ml_get_pos(pos)); } /* @@ -2390,12 +2384,12 @@ int get_keystroke(void) } break; } - if (has_mbyte) { - if (MB_BYTE2LEN(n) > len) - continue; /* more bytes to get */ - buf[len >= buflen ? buflen - 1 : len] = NUL; - n = utf_ptr2char(buf); + if (MB_BYTE2LEN(n) > len) { + // more bytes to get. + continue; } + buf[len >= buflen ? buflen - 1 : len] = NUL; + n = utf_ptr2char(buf); #ifdef UNIX if (n == intr_char) n = ESC; diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 1b711bd881..a4fb16280c 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -772,14 +772,9 @@ static int get_equi_class(char_u **pp) char_u *p = *pp; if (p[1] == '=') { - if (has_mbyte) - l = (*mb_ptr2len)(p + 2); + l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '=' && p[l + 3] == ']') { - if (has_mbyte) { - c = utf_ptr2char(p + 2); - } else { - c = p[2]; - } + c = utf_ptr2char(p + 2); *pp += l + 4; return c; } @@ -1108,14 +1103,9 @@ static int get_coll_element(char_u **pp) char_u *p = *pp; if (p[0] != NUL && p[1] == '.') { - if (has_mbyte) - l = (*mb_ptr2len)(p + 2); + l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '.' && p[l + 3] == ']') { - if (has_mbyte) { - c = utf_ptr2char(p + 2); - } else { - c = p[2]; - } + c = utf_ptr2char(p + 2); *pp += l + 4; return c; } @@ -1301,11 +1291,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) } if (OP(scan) == EXACTLY) { - if (has_mbyte) { - r->regstart = utf_ptr2char(OPERAND(scan)); - } else { - r->regstart = *OPERAND(scan); - } + r->regstart = utf_ptr2char(OPERAND(scan)); } else if (OP(scan) == BOW || OP(scan) == EOW || OP(scan) == NOTHING @@ -1313,11 +1299,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) || OP(scan) == MCLOSE + 0 || OP(scan) == NCLOSE) { char_u *regnext_scan = regnext(scan); if (OP(regnext_scan) == EXACTLY) { - if (has_mbyte) { - r->regstart = utf_ptr2char(OPERAND(regnext_scan)); - } else { - r->regstart = *OPERAND(regnext_scan); - } + r->regstart = utf_ptr2char(OPERAND(regnext_scan)); } } @@ -2416,20 +2398,16 @@ collection: break; } } else { - if (has_mbyte) { - int len; - - /* produce a multibyte character, including any - * following composing characters */ - startc = utf_ptr2char(regparse); - len = (*mb_ptr2len)(regparse); - if (enc_utf8 && utf_char2len(startc) != len) - startc = -1; /* composing chars */ - while (--len >= 0) - regc(*regparse++); - } else { - startc = *regparse++; - regc(startc); + // produce a multibyte character, including any + // following composing characters. + startc = utf_ptr2char(regparse); + int len = utfc_ptr2len(regparse); + if (utf_char2len(startc) != len) { + // composing chars + startc = -1; + } + while (--len >= 0) { + regc(*regparse++); } } } @@ -2910,19 +2888,13 @@ static int peekchr(void) * Next character can never be (made) magic? * Then backslashing it won't do anything. */ - if (has_mbyte) { - curchr = utf_ptr2char(regparse + 1); - } else { - curchr = c; - } + curchr = utf_ptr2char(regparse + 1); } break; } default: - if (has_mbyte) { - curchr = utf_ptr2char(regparse); - } + curchr = utf_ptr2char(regparse); } return curchr; @@ -3474,11 +3446,7 @@ static long bt_regexec_both(char_u *line, if (prog->regmust != NULL) { int c; - if (has_mbyte) { - c = utf_ptr2char(prog->regmust); - } else { - c = *prog->regmust; - } + c = utf_ptr2char(prog->regmust); s = line + col; // This is used very often, esp. for ":global". Use two versions of @@ -3509,17 +3477,11 @@ static long bt_regexec_both(char_u *line, /* Simplest case: Anchored match need be tried only once. */ if (prog->reganch) { - int c; - - if (has_mbyte) { - c = utf_ptr2char(regline + col); - } else { - c = regline[col]; - } + int c = utf_ptr2char(regline + col); if (prog->regstart == NUL || prog->regstart == c || (rex.reg_ic - && (((enc_utf8 && utf_fold(prog->regstart) == utf_fold(c))) + && (utf_fold(prog->regstart) == utf_fold(c) || (c < 255 && prog->regstart < 255 && mb_tolower(prog->regstart) == mb_tolower(c))))) { retval = regtry(prog, col); @@ -3866,13 +3828,10 @@ regmatch ( } else if (rex.reg_line_lbr && WITH_NL(op) && *reginput == '\n') { ADVANCE_REGINPUT(); } else { - if (WITH_NL(op)) + if (WITH_NL(op)) { op -= ADD_NL; - if (has_mbyte) { - c = utf_ptr2char(reginput); - } else { - c = *reginput; } + c = utf_ptr2char(reginput); switch (op) { case BOL: if (reginput != regline) @@ -6791,20 +6750,20 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, } c = *src++; } - } else if (has_mbyte) { + } else { c = utf_ptr2char(src - 1); } - - /* Write to buffer, if copy is set. */ - if (func_one != (fptr_T)NULL) - /* Turbo C complains without the typecast */ + // Write to buffer, if copy is set. + if (func_one != NULL) { func_one = (fptr_T)(func_one(&cc, c)); - else if (func_all != (fptr_T)NULL) - /* Turbo C complains without the typecast */ - func_all = (fptr_T)(func_all(&cc, c)); - else /* just copy */ - cc = c; - + } else { + if (func_all != NULL) { + func_all = (fptr_T)(func_all(&cc, c)); + } else { + // just copy + cc = c; + } + } if (has_mbyte) { int totlen = mb_ptr2len(src - 1); @@ -6888,11 +6847,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, } dst += 2; } else { - if (has_mbyte) { - c = utf_ptr2char(s); - } else { - c = *s; - } + c = utf_ptr2char(s); if (func_one != (fptr_T)NULL) /* Turbo C complains without the typecast */ diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 1a44a6119e..0e0ebdd64b 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -5033,13 +5033,8 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, int curc; int clen; - if (has_mbyte) { - curc = utf_ptr2char(reginput); - clen = (*mb_ptr2len)(reginput); - } else { - curc = *reginput; - clen = 1; - } + curc = utf_ptr2char(reginput); + clen = utfc_ptr2len(reginput); if (curc == NUL) { clen = 0; go_to_nextline = false; diff --git a/src/nvim/search.c b/src/nvim/search.c index 472b98a501..95929f0eb4 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1120,8 +1120,8 @@ int do_search( msgbuf = xmalloc(STRLEN(p) + 40); { msgbuf[0] = dirc; - if (enc_utf8 && utf_iscomposing(utf_ptr2char(p))) { - /* Use a space to draw the composing char on. */ + if (utf_iscomposing(utf_ptr2char(p))) { + // Use a space to draw the composing char on. msgbuf[1] = ' '; STRCPY(msgbuf + 2, p); } else diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 3d393acadb..80406e5329 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2619,16 +2619,11 @@ static bool spell_iswordp(char_u *p, win_T *wp) // Unlike spell_iswordp() this doesn't check for "midword" characters. bool spell_iswordp_nmw(const char_u *p, win_T *wp) { - int c; - - if (has_mbyte) { - c = utf_ptr2char(p); - if (c > 255) { - return spell_mb_isword_class(mb_get_class(p), wp); - } - return spelltab.st_isw[c]; + int c = utf_ptr2char(p); + if (c > 255) { + return spell_mb_isword_class(mb_get_class(p), wp); } - return spelltab.st_isw[*p]; + return spelltab.st_isw[c]; } // Returns true if word class indicates a word character. @@ -4316,7 +4311,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so && sp->ts_twordlen > sp->ts_tcharlen) { p = tword + sp->ts_twordlen - sp->ts_tcharlen; c = utf_ptr2char(p); - if (enc_utf8 && utf_iscomposing(c)) { + if (utf_iscomposing(c)) { // Inserting a composing char doesn't // count that much. sp->ts_score -= SCORE_INS - SCORE_INSCOMP; @@ -4388,19 +4383,14 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // score if the same character is following "nn" -> "n". It's // a bit illogical for soundfold tree but it does give better // results. - if (has_mbyte) { - c = utf_ptr2char(fword + sp->ts_fidx); - stack[depth].ts_fidx += MB_PTR2LEN(fword + sp->ts_fidx); - if (enc_utf8 && utf_iscomposing(c)) { - stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; - } else if (c == utf_ptr2char(fword + stack[depth].ts_fidx)) { - stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; - } - } else { - ++stack[depth].ts_fidx; - if (fword[sp->ts_fidx] == fword[sp->ts_fidx + 1]) - stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; + c = utf_ptr2char(fword + sp->ts_fidx); + stack[depth].ts_fidx += MB_PTR2LEN(fword + sp->ts_fidx); + if (utf_iscomposing(c)) { + stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; + } else if (c == utf_ptr2char(fword + stack[depth].ts_fidx)) { + stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; } + break; } // FALLTHROUGH @@ -4515,24 +4505,14 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so break; } - if (has_mbyte) { - n = MB_CPTR2LEN(p); - c = utf_ptr2char(p); - if (p[n] == NUL) { - c2 = NUL; - } else if (!soundfold && !spell_iswordp(p + n, curwin)) { - c2 = c; // don't swap non-word char - } else { - c2 = utf_ptr2char(p + n); - } + n = MB_CPTR2LEN(p); + c = utf_ptr2char(p); + if (p[n] == NUL) { + c2 = NUL; + } else if (!soundfold && !spell_iswordp(p + n, curwin)) { + c2 = c; // don't swap non-word char } else { - if (p[1] == NUL) { - c2 = NUL; - } else if (!soundfold && !spell_iswordp(p + 1, curwin)) { - c2 = c; // don't swap non-word char - } else { - c2 = p[1]; - } + c2 = utf_ptr2char(p + n); } // When the second character is NUL we can't swap. @@ -4578,39 +4558,25 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNSWAP: // Undo the STATE_SWAP swap: "21" -> "12". p = fword + sp->ts_fidx; - if (has_mbyte) { - n = MB_PTR2LEN(p); - c = utf_ptr2char(p + n); - memmove(p + MB_PTR2LEN(p + n), p, n); - mb_char2bytes(c, p); - } else { - c = *p; - *p = p[1]; - p[1] = c; - } + n = MB_PTR2LEN(p); + c = utf_ptr2char(p + n); + memmove(p + MB_PTR2LEN(p + n), p, n); + mb_char2bytes(c, p); + // FALLTHROUGH case STATE_SWAP3: // Swap two bytes, skipping one: "123" -> "321". We change // "fword" here, it's changed back afterwards at STATE_UNSWAP3. p = fword + sp->ts_fidx; - if (has_mbyte) { - n = MB_CPTR2LEN(p); - c = utf_ptr2char(p); - fl = MB_CPTR2LEN(p + n); - c2 = utf_ptr2char(p + n); - if (!soundfold && !spell_iswordp(p + n + fl, curwin)) { - c3 = c; // don't swap non-word char - } else { - c3 = utf_ptr2char(p + n + fl); - } + n = MB_CPTR2LEN(p); + c = utf_ptr2char(p); + fl = MB_CPTR2LEN(p + n); + c2 = utf_ptr2char(p + n); + if (!soundfold && !spell_iswordp(p + n + fl, curwin)) { + c3 = c; // don't swap non-word char } else { - c = *p; - c2 = p[1]; - if (!soundfold && !spell_iswordp(p + 2, curwin)) - c3 = c; // don't swap non-word char - else - c3 = p[2]; + c3 = utf_ptr2char(p + n + fl); } // When characters are identical: "121" then SWAP3 result is @@ -4654,22 +4620,15 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNSWAP3: // Undo STATE_SWAP3: "321" -> "123" p = fword + sp->ts_fidx; - if (has_mbyte) { - n = MB_PTR2LEN(p); - c2 = utf_ptr2char(p + n); - fl = MB_PTR2LEN(p + n); - c = utf_ptr2char(p + n + fl); - tl = MB_PTR2LEN(p + n + fl); - memmove(p + fl + tl, p, n); - mb_char2bytes(c, p); - mb_char2bytes(c2, p + tl); - p = p + tl; - } else { - c = *p; - *p = p[2]; - p[2] = c; - ++p; - } + n = MB_PTR2LEN(p); + c2 = utf_ptr2char(p + n); + fl = MB_PTR2LEN(p + n); + c = utf_ptr2char(p + n + fl); + tl = MB_PTR2LEN(p + n + fl); + memmove(p + fl + tl, p, n); + mb_char2bytes(c, p); + mb_char2bytes(c2, p + tl); + p = p + tl; if (!soundfold && !spell_iswordp(p, curwin)) { // Middle char is not a word char, skip the rotate. First and @@ -4717,19 +4676,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNROT3L: // Undo ROT3L: "231" -> "123" p = fword + sp->ts_fidx; - if (has_mbyte) { - n = MB_PTR2LEN(p); - n += MB_PTR2LEN(p + n); - c = utf_ptr2char(p + n); - tl = MB_PTR2LEN(p + n); - memmove(p + tl, p, n); - mb_char2bytes(c, p); - } else { - c = p[2]; - p[2] = p[1]; - p[1] = *p; - *p = c; - } + n = MB_PTR2LEN(p); + n += MB_PTR2LEN(p + n); + c = utf_ptr2char(p + n); + tl = MB_PTR2LEN(p + n); + memmove(p + tl, p, n); + mb_char2bytes(c, p); // Rotate three bytes right: "123" -> "312". We change "fword" // here, it's changed back afterwards at STATE_UNROT3R. @@ -4745,21 +4697,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so sp->ts_state = STATE_UNROT3R; ++depth; p = fword + sp->ts_fidx; - if (has_mbyte) { - n = MB_CPTR2LEN(p); - n += MB_CPTR2LEN(p + n); - c = utf_ptr2char(p + n); - tl = MB_CPTR2LEN(p + n); - memmove(p + tl, p, n); - mb_char2bytes(c, p); - stack[depth].ts_fidxtry = sp->ts_fidx + n + tl; - } else { - c = p[2]; - p[2] = p[1]; - p[1] = *p; - *p = c; - stack[depth].ts_fidxtry = sp->ts_fidx + 3; - } + n = MB_CPTR2LEN(p); + n += MB_CPTR2LEN(p + n); + c = utf_ptr2char(p + n); + tl = MB_CPTR2LEN(p + n); + memmove(p + tl, p, n); + mb_char2bytes(c, p); + stack[depth].ts_fidxtry = sp->ts_fidx + n + tl; } else { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; @@ -4769,19 +4713,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNROT3R: // Undo ROT3R: "312" -> "123" p = fword + sp->ts_fidx; - if (has_mbyte) { - c = utf_ptr2char(p); - tl = MB_PTR2LEN(p); - n = MB_PTR2LEN(p + tl); - n += MB_PTR2LEN(p + tl + n); - memmove(p, p + tl, n); - mb_char2bytes(c, p + n); - } else { - c = *p; - *p = p[1]; - p[1] = p[2]; - p[2] = c; - } + c = utf_ptr2char(p); + tl = MB_PTR2LEN(p); + n = MB_PTR2LEN(p + tl); + n += MB_PTR2LEN(p + tl + n); + memmove(p, p + tl, n); + mb_char2bytes(c, p + n); + // FALLTHROUGH case STATE_REP_INI: @@ -5666,11 +5604,7 @@ add_suggestion ( break; MB_PTR_BACK(goodword, pgood); MB_PTR_BACK(su->su_badptr, pbad); - if (has_mbyte) { - if (utf_ptr2char(pgood) != utf_ptr2char(pbad)) { - break; - } - } else if (*pgood != *pbad) { + if (utf_ptr2char(pgood) != utf_ptr2char(pbad)) { break; } } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 2f142e65c9..d7c23742ba 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4101,13 +4101,9 @@ get_syn_options( return NULL; } } else if (flagtab[fidx].argtype == 11 && arg[5] == '=') { - /* cchar=? */ - if (has_mbyte) { - *conceal_char = utf_ptr2char(arg + 6); - arg += mb_ptr2len(arg + 6) - 1; - } else { - *conceal_char = arg[6]; - } + // cchar=? + *conceal_char = utf_ptr2char(arg + 6); + arg += mb_ptr2len(arg + 6) - 1; if (!vim_isprintc_strict(*conceal_char)) { EMSG(_("E844: invalid cchar value")); return NULL; -- cgit From 5cecd7a93aba83cd477519974fc33fadbdcfdc87 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Sun, 1 Jul 2018 22:58:42 +0300 Subject: style: fixing minor issues noted in code review. --- src/nvim/ex_docmd.c | 18 ++---------- src/nvim/ex_getln.c | 37 +++++++---------------- src/nvim/fold.c | 6 ++-- src/nvim/message.c | 37 +++++++---------------- src/nvim/ops.c | 16 ++++------ src/nvim/option.c | 81 +++++++++++++++++---------------------------------- src/nvim/regexp.c | 19 +++++------- src/nvim/regexp_nfa.c | 7 ++--- src/nvim/spell.c | 62 ++++++++++++++++++--------------------- 9 files changed, 96 insertions(+), 187 deletions(-) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 0ff0b1b574..3d3d02fd71 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2899,11 +2899,7 @@ const char * set_one_cmd_context( xp->xp_pattern = skipwhite((const char_u *)arg); p = (const char *)xp->xp_pattern; while (*p != NUL) { - if (has_mbyte) { - c = utf_ptr2char((const char_u *)p); - } else { - c = (uint8_t)(*p); - } + c = utf_ptr2char((const char_u *)p); if (c == '\\' && p[1] != NUL) { p++; } else if (c == '`') { @@ -2921,19 +2917,11 @@ const char * set_one_cmd_context( || ascii_iswhite(c)) { len = 0; /* avoid getting stuck when space is in 'isfname' */ while (*p != NUL) { - if (has_mbyte) { - c = utf_ptr2char((const char_u *)p); - } else { - c = *p; - } + c = utf_ptr2char((const char_u *)p); if (c == '`' || vim_isfilec_or_wc(c)) { break; } - if (has_mbyte) { - len = (size_t)(*mb_ptr2len)((const char_u *)p); - } else { - len = 1; - } + len = (size_t)utfc_ptr2len((const char_u *)p); MB_PTR_ADV(p); } if (in_quote) { diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 52f4f3bde4..353f724fe4 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3327,17 +3327,11 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) /* Locate start of last word in the cmd buffer. */ for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) { - if (has_mbyte) { - len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; - if (!vim_iswordc(utf_ptr2char(w - len))) { - break; - } - w -= len; - } else { - if (!vim_iswordc(w[-1])) - break; - --w; + len = utf_head_off(ccline.cmdbuff, w - 1) + 1; + if (!vim_iswordc(utf_ptr2char(w - len))) { + break; } + w -= len; } len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) @@ -3838,24 +3832,13 @@ ExpandOne ( // Find longest common part if (mode == WILD_LONGEST && xp->xp_numfiles > 0) { - size_t len; - size_t mb_len = 1; - int c0; - int ci; + size_t len = 0; - for (len = 0; xp->xp_files[0][len]; len += mb_len) { - if (has_mbyte) { - mb_len = (* mb_ptr2len)(&xp->xp_files[0][len]); - c0 = utf_ptr2char(&xp->xp_files[0][len]); - } else { - c0 = xp->xp_files[0][len]; - } - for (i = 1; i < xp->xp_numfiles; ++i) { - if (has_mbyte) { - ci = utf_ptr2char(&xp->xp_files[i][len]); - } else { - ci = xp->xp_files[i][len]; - } + for (size_t mb_len; xp->xp_files[0][len]; len += mb_len) { + mb_len = utfc_ptr2len(&xp->xp_files[0][len]); + int c0 = utf_ptr2char(&xp->xp_files[0][len]); + for (i = 1; i < xp->xp_numfiles; i++) { + int ci = utf_ptr2char(&xp->xp_files[i][len]); if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES || xp->xp_context == EXPAND_FILES diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 2781643a5d..6aae927483 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1763,10 +1763,10 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, if (text != NULL) { /* Replace unprintable characters, if there are any. But * replace a TAB with a space. */ - for (p = text; *p != NUL; ++p) { - int len; + for (p = text; *p != NUL; p++) { + int len = utfc_ptr2len(p); - if (has_mbyte && (len = (*mb_ptr2len)(p)) > 1) { + if (len > 1) { if (!vim_isprintc(utf_ptr2char(p))) { break; } diff --git a/src/nvim/message.c b/src/nvim/message.c index ddbc17439b..947cd0735e 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -2866,15 +2866,12 @@ do_dialog ( // Make the character lowercase, as chars in "hotkeys" are. c = mb_tolower(c); retval = 1; - for (i = 0; hotkeys[i]; ++i) { - if (has_mbyte) { - if (utf_ptr2char(hotkeys + i) == c) { - break; - } - i += (*mb_ptr2len)(hotkeys + i) - 1; - } else if (hotkeys[i] == c) + for (i = 0; hotkeys[i]; i++) { + if (utf_ptr2char(hotkeys + i) == c) { break; - ++retval; + } + i += utfc_ptr2len(hotkeys + i) - 1; + retval++; } if (hotkeys[i]) break; @@ -2906,25 +2903,13 @@ copy_char ( int lowercase /* make character lower case */ ) { - int len; - int c; - - if (has_mbyte) { - if (lowercase) { - c = mb_tolower(utf_ptr2char(from)); - return (*mb_char2bytes)(c, to); - } else { - len = (*mb_ptr2len)(from); - memmove(to, from, (size_t)len); - return len; - } - } else { - if (lowercase) - *to = (char_u)TOLOWER_LOC(*from); - else - *to = *from; - return 1; + if (lowercase) { + int c = mb_tolower(utf_ptr2char(from)); + return utf_char2bytes(c, to); } + int len = utfc_ptr2len(from); + memmove(to, from, (size_t)len); + return len; } #define HAS_HOTKEY_LEN 30 diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 05955f4215..041443d472 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3639,18 +3639,12 @@ int do_join(size_t count, sumsize += currsize + spaces[t]; endcurr1 = endcurr2 = NUL; if (insert_space && currsize > 0) { - if (has_mbyte) { - cend = curr + currsize; + cend = curr + currsize; + MB_PTR_BACK(curr, cend); + endcurr1 = utf_ptr2char(cend); + if (cend > curr) { MB_PTR_BACK(curr, cend); - endcurr1 = utf_ptr2char(cend); - if (cend > curr) { - MB_PTR_BACK(curr, cend); - endcurr2 = utf_ptr2char(cend); - } - } else { - endcurr1 = *(curr + currsize - 1); - if (currsize > 1) - endcurr2 = *(curr + currsize - 2); + endcurr2 = utf_ptr2char(cend); } } line_breakcheck(); diff --git a/src/nvim/option.c b/src/nvim/option.c index c06485c63e..8e2264c6a7 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -6849,66 +6849,37 @@ int get_sts_value(void) */ void find_mps_values(int *initc, int *findc, int *backwards, int switchit) { - char_u *ptr; + char_u *ptr = curbuf->b_p_mps; - ptr = curbuf->b_p_mps; while (*ptr != NUL) { - if (has_mbyte) { - char_u *prev; - - if (utf_ptr2char(ptr) == *initc) { - if (switchit) { - *findc = *initc; - *initc = utf_ptr2char(ptr + mb_ptr2len(ptr) + 1); - *backwards = true; - } else { - *findc = utf_ptr2char(ptr + mb_ptr2len(ptr) + 1); - *backwards = false; - } - return; - } - prev = ptr; - ptr += mb_ptr2len(ptr) + 1; - if (utf_ptr2char(ptr) == *initc) { - if (switchit) { - *findc = *initc; - *initc = utf_ptr2char(prev); - *backwards = false; - } else { - *findc = utf_ptr2char(prev); - *backwards = true; - } - return; - } - ptr += mb_ptr2len(ptr); - } else { - if (*ptr == *initc) { - if (switchit) { - *backwards = TRUE; - *findc = *initc; - *initc = ptr[2]; - } else { - *backwards = FALSE; - *findc = ptr[2]; - } - return; + if (utf_ptr2char(ptr) == *initc) { + if (switchit) { + *findc = *initc; + *initc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1); + *backwards = true; + } else { + *findc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1); + *backwards = false; } - ptr += 2; - if (*ptr == *initc) { - if (switchit) { - *backwards = FALSE; - *findc = *initc; - *initc = ptr[-2]; - } else { - *backwards = TRUE; - *findc = ptr[-2]; - } - return; + return; + } + char_u *prev = ptr; + ptr += utfc_ptr2len(ptr) + 1; + if (utf_ptr2char(ptr) == *initc) { + if (switchit) { + *findc = *initc; + *initc = utf_ptr2char(prev); + *backwards = false; + } else { + *findc = utf_ptr2char(prev); + *backwards = true; } - ++ptr; + return; + } + ptr += utfc_ptr2len(ptr); + if (*ptr == ',') { + ptr++; } - if (*ptr == ',') - ++ptr; } } diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index a4fb16280c..be6c43493b 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1103,7 +1103,7 @@ static int get_coll_element(char_u **pp) char_u *p = *pp; if (p[0] != NUL && p[1] == '.') { - l = (*mb_ptr2len)(p + 2); + l = utfc_ptr2len(p + 2); if (p[l + 2] == '.' && p[l + 3] == ']') { c = utf_ptr2char(p + 2); *pp += l + 4; @@ -3444,9 +3444,7 @@ static long bt_regexec_both(char_u *line, /* If there is a "must appear" string, look for it. */ if (prog->regmust != NULL) { - int c; - - c = utf_ptr2char(prog->regmust); + int c = utf_ptr2char(prog->regmust); s = line + col; // This is used very often, esp. for ":global". Use two versions of @@ -5441,7 +5439,7 @@ do_class: } } else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) { scan++; - } else if (has_mbyte && (len = (*mb_ptr2len)(scan)) > 1) { + } else if ((len = utfc_ptr2len(scan)) > 1) { if ((cstrchr(opnd, utf_ptr2char(scan)) == NULL) == testval) { break; } @@ -6756,14 +6754,13 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, // Write to buffer, if copy is set. if (func_one != NULL) { func_one = (fptr_T)(func_one(&cc, c)); + } else if (func_all != NULL) { + func_all = (fptr_T)(func_all(&cc, c)); } else { - if (func_all != NULL) { - func_all = (fptr_T)(func_all(&cc, c)); - } else { - // just copy - cc = c; - } + // just copy + cc = c; } + if (has_mbyte) { int totlen = mb_ptr2len(src - 1); diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 0e0ebdd64b..deef3042d2 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -5030,11 +5030,8 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, * Run for each character. */ for (;; ) { - int curc; - int clen; - - curc = utf_ptr2char(reginput); - clen = utfc_ptr2len(reginput); + int curc = utf_ptr2char(reginput); + int clen = utfc_ptr2len(reginput); if (curc == NUL) { clen = 0; go_to_nextline = false; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 80406e5329..7f1cc98849 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -4297,12 +4297,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so && utf_iscomposing(utf_ptr2char(fword + sp->ts_fcharstart))) { sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP; - } else if (!soundfold && slang->sl_has_map - && similar_chars(slang, - utf_ptr2char(tword + sp->ts_twordlen - - sp->ts_tcharlen), - utf_ptr2char(fword + - sp->ts_fcharstart))) { + } else if ( + !soundfold + && slang->sl_has_map + && similar_chars( + slang, + utf_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen), + utf_ptr2char(fword + sp->ts_fcharstart))) { // For a similar character adjust score from // SCORE_SUBST to SCORE_SIMILAR. sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR; @@ -4520,21 +4521,22 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; break; - } + } - // When characters are identical, swap won't do anything. - // Also get here if the second char is not a word character. - if (c == c2) { - PROF_STORE(sp->ts_state) - sp->ts_state = STATE_SWAP3; - break; - } - if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP)) { - go_deeper(stack, depth, SCORE_SWAP); + // When characters are identical, swap won't do anything. + // Also get here if the second char is not a word character. + if (c == c2) { + PROF_STORE(sp->ts_state) + sp->ts_state = STATE_SWAP3; + break; + } + if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP)) { + go_deeper(stack, depth, SCORE_SWAP); #ifdef DEBUG_TRIEWALK - sprintf(changename[depth], "%.*s-%s: swap %c and %c", - sp->ts_twordlen, tword, fword + sp->ts_fidx, - c, c2); + snprintf(changename[depth], sizeof(changename[0]), + "%.*s-%s: swap %c and %c", + sp->ts_twordlen, tword, fword + sp->ts_fidx, + c, c2); #endif PROF_STORE(sp->ts_state) sp->ts_state = STATE_UNSWAP; @@ -4652,21 +4654,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so sp->ts_state = STATE_UNROT3L; ++depth; p = fword + sp->ts_fidx; - if (has_mbyte) { - n = MB_CPTR2LEN(p); - c = utf_ptr2char(p); - fl = MB_CPTR2LEN(p + n); - fl += MB_CPTR2LEN(p + n + fl); - memmove(p, p + n, fl); - mb_char2bytes(c, p + fl); - stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; - } else { - c = *p; - *p = p[1]; - p[1] = p[2]; - p[2] = c; - stack[depth].ts_fidxtry = sp->ts_fidx + 3; - } + n = MB_CPTR2LEN(p); + c = utf_ptr2char(p); + fl = MB_CPTR2LEN(p + n); + fl += MB_CPTR2LEN(p + n + fl); + memmove(p, p + n, fl); + utf_char2bytes(c, p + fl); + stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; } else { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; -- cgit