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; } - -