From cbdbc4f63d68a6b17b9eea5c67130e37d3d0f278 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Sun, 2 Sep 2018 00:58:30 +0300 Subject: Refactor: Remove occurences of mb_char2bytes --- src/nvim/arabic.c | 2 +- src/nvim/digraph.c | 2 +- src/nvim/edit.c | 8 ++++---- src/nvim/eval.c | 8 ++++---- src/nvim/ex_getln.c | 10 +++++----- src/nvim/getchar.c | 6 +++--- src/nvim/keymap.c | 4 ++-- src/nvim/mbyte.h | 1 - src/nvim/message.c | 2 +- src/nvim/misc1.c | 2 +- src/nvim/ops.c | 2 +- src/nvim/regexp.c | 6 +++--- src/nvim/regexp_nfa.c | 2 +- src/nvim/screen.c | 8 ++++---- src/nvim/search.c | 6 +++--- src/nvim/spell.c | 32 ++++++++++++++++---------------- src/nvim/spellfile.c | 8 ++++---- 17 files changed, 54 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/nvim/arabic.c b/src/nvim/arabic.c index 7cf9025933..7f12c0c798 100644 --- a/src/nvim/arabic.c +++ b/src/nvim/arabic.c @@ -761,7 +761,7 @@ int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1, char_u buf[MB_MAXBYTES + 1]; // Update the first byte of the character - (*mb_char2bytes)(curr_c, buf); + utf_char2bytes(curr_c, buf); *ccp = buf[0]; } diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index c0915224e5..54508018b5 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1708,7 +1708,7 @@ static void printdigraph(digr_T *dp) if (utf_iscomposing(dp->result)) { *p++ = ' '; } - p += (*mb_char2bytes)(dp->result, p); + p += utf_char2bytes(dp->result, p); *p = NUL; msg_outtrans_attr(buf, HL_ATTR(HLF_8)); diff --git a/src/nvim/edit.c b/src/nvim/edit.c index a20661bb16..908dd90cdb 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2132,7 +2132,7 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int i = 0; while (i < actual_len && (p - IObuff + 6) < IOSIZE) { if (has_mbyte) { - p += (*mb_char2bytes)(wca[i++], p); + p += utf_char2bytes(wca[i++], p); } else { *(p++) = wca[i++]; } @@ -3087,7 +3087,7 @@ static void ins_compl_addleader(int c) if (has_mbyte && (cc = (*mb_char2len)(c)) > 1) { char_u buf[MB_MAXBYTES + 1]; - (*mb_char2bytes)(c, buf); + utf_char2bytes(c, buf); buf[cc] = NUL; ins_char_bytes(buf, cc); } else { @@ -5337,7 +5337,7 @@ insertchar ( if (has_mbyte && (cc = (*mb_char2len)(c)) > 1) { char_u buf[MB_MAXBYTES + 1]; - (*mb_char2bytes)(c, buf); + utf_char2bytes(c, buf); buf[cc] = NUL; ins_char_bytes(buf, cc); AppendCharToRedobuff(c); @@ -8661,7 +8661,7 @@ static char_u *do_insert_char_pre(int c) return NULL; } if (has_mbyte) { - buf[(*mb_char2bytes)(c, (char_u *) buf)] = NUL; + buf[utf_char2bytes(c, (char_u *) buf)] = NUL; } else { buf[0] = c; buf[1] = NUL; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d750a47588..b56032437b 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4719,7 +4719,7 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) /* For "\u" store the number according to * 'encoding'. */ if (c != 'X') - name += (*mb_char2bytes)(nr, name); + name += utf_char2bytes(nr, name); else *name++ = nr; } @@ -9478,7 +9478,7 @@ static void f_getchar(typval_T *argvars, typval_T *rettv, FunPtr fptr) temp[i++] = K_SECOND(n); temp[i++] = K_THIRD(n); } else if (has_mbyte) - i += (*mb_char2bytes)(n, temp + i); + i += utf_char2bytes(n, temp + i); else temp[i++] = n; temp[i++] = NUL; @@ -10010,7 +10010,7 @@ static void f_getmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (cur->conceal_char) { char buf[MB_MAXBYTES + 1]; - buf[(*mb_char2bytes)((int)cur->conceal_char, (char_u *)buf)] = NUL; + buf[utf_char2bytes((int)cur->conceal_char, (char_u *)buf)] = NUL; tv_dict_add_str(dict, S_LEN("conceal"), buf); } @@ -18347,7 +18347,7 @@ void set_vim_var_char(int c) char buf[MB_MAXBYTES + 1]; if (has_mbyte) { - buf[(*mb_char2bytes)(c, (char_u *) buf)] = NUL; + buf[utf_char2bytes(c, (char_u *) buf)] = NUL; } else { buf[0] = c; buf[1] = NUL; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 31231fe725..bfca888dc5 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1763,7 +1763,7 @@ static int command_line_handle_key(CommandLineState *s) put_on_cmdline(get_special_key_name(s->c, mod_mask), -1, true); } else { if (has_mbyte) { - s->j = (*mb_char2bytes)(s->c, IObuff); + s->j = utf_char2bytes(s->c, IObuff); IObuff[s->j] = NUL; // exclude composing chars put_on_cmdline(IObuff, s->j, true); } else { @@ -2373,7 +2373,7 @@ redraw: c1 = '?'; } if (has_mbyte) { - len = (*mb_char2bytes)(c1, (char_u *)line_ga.ga_data + line_ga.ga_len); + len = utf_char2bytes(c1, (char_u *)line_ga.ga_data + line_ga.ga_len); } else { len = 1; ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; @@ -2897,11 +2897,11 @@ static void draw_cmdline(int start, int len) u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); - newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); + newlen += utf_char2bytes(u8c, arshape_buf + newlen); if (u8cc[0] != 0) { - newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); + newlen += utf_char2bytes(u8cc[0], arshape_buf + newlen); if (u8cc[1] != 0) - newlen += (*mb_char2bytes)(u8cc[1], + newlen += utf_char2bytes(u8cc[1], arshape_buf + newlen); } } else { diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index f13bede076..544d518ff1 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -315,7 +315,7 @@ static void add_char_buff(buffheader_T *buf, int c) if (IS_SPECIAL(c)) { len = 1; } else { - len = mb_char2bytes(c, bytes); + len = utf_char2bytes(c, bytes); } for (int i = 0; i < len; i++) { @@ -978,7 +978,7 @@ void ins_char_typebuf(int c) buf[2] = (char_u)K_THIRD(c); buf[3] = NUL; } else { - buf[(*mb_char2bytes)(c, buf)] = NUL; + buf[utf_char2bytes(c, buf)] = NUL; } (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent); } @@ -3661,7 +3661,7 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) /* if ABBR_OFF has been added, remove it here */ if (c >= ABBR_OFF) c -= ABBR_OFF; - j += (*mb_char2bytes)(c, tb + j); + j += utf_char2bytes(c, tb + j); } else { tb[j++] = (char_u)c; } diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index 3cc74c0044..fad4722661 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -466,7 +466,7 @@ char_u *get_special_key_name(int c, int modifiers) /* Not a special key, only modifiers, output directly */ else { if (has_mbyte && (*mb_char2len)(c) > 1) - idx += (*mb_char2bytes)(c, string + idx); + idx += utf_char2bytes(c, string + idx); else if (vim_isprintc(c)) string[idx++] = (char_u)c; else { @@ -525,7 +525,7 @@ unsigned int trans_special(const char_u **srcp, const size_t src_len, dst[dlen++] = (char_u)KEY2TERMCAP0(key); dst[dlen++] = KEY2TERMCAP1(key); } else if (has_mbyte && !keycode) { - dlen += (unsigned int)(*mb_char2bytes)(key, dst + dlen); + dlen += (unsigned int)utf_char2bytes(key, dst + dlen); } else if (keycode) { char_u *after = add_char2buf(key, dst + dlen); assert(after >= dst && (uintmax_t)(after - dst) <= UINT_MAX); diff --git a/src/nvim/mbyte.h b/src/nvim/mbyte.h index 6656780df5..70073a8540 100644 --- a/src/nvim/mbyte.h +++ b/src/nvim/mbyte.h @@ -48,7 +48,6 @@ enum { MAX_MCO = 6 }; // TODO(bfredl): eventually we should keep only one of the namings #define mb_ptr2len utfc_ptr2len #define mb_char2len utf_char2len -#define mb_char2bytes utf_char2bytes #define mb_char2cells utf_char2cells /// Flags for vimconv_T diff --git a/src/nvim/message.c b/src/nvim/message.c index 0821ff3489..80f4f1defb 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1121,7 +1121,7 @@ void msg_putchar_attr(int c, int attr) buf[2] = (char)K_THIRD(c); buf[3] = NUL; } else { - buf[(*mb_char2bytes)(c, (char_u *)buf)] = NUL; + buf[utf_char2bytes(c, (char_u *)buf)] = NUL; } msg_puts_attr(buf, attr); } diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 50cc9dae02..cb53421bb5 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -1398,7 +1398,7 @@ void ins_bytes_len(char_u *p, size_t len) void ins_char(int c) { char_u buf[MB_MAXBYTES + 1]; - size_t n = (size_t)(*mb_char2bytes)(c, buf); + size_t n = (size_t)utf_char2bytes(c, buf); // When "c" is 0x100, 0x200, etc. we don't want to insert a NUL byte. // Happens for CTRL-Vu9900. diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 23948df769..fcfadbfd28 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1739,7 +1739,7 @@ int op_replace(oparg_T *oap, int c) int newp_len = bd.textcol + bd.startspaces; if (has_mbyte) { while (--num_chars >= 0) { - newp_len += (*mb_char2bytes)(c, newp + newp_len); + newp_len += utf_char2bytes(c, newp + newp_len); } } else { memset(newp + newp_len, c, (size_t)numc); diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index bbc161ee3e..7152a38815 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -2543,7 +2543,7 @@ static void regmbc(int c) if (regcode == JUST_CALC_SIZE) regsize += (*mb_char2len)(c); else - regcode += (*mb_char2bytes)(c, regcode); + regcode += utf_char2bytes(c, regcode); } /* @@ -6763,7 +6763,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, int totlen = mb_ptr2len(src - 1); if (copy) - mb_char2bytes(cc, dst); + utf_char2bytes(cc, dst); dst += mb_char2len(cc) - 1; if (enc_utf8) { int clen = utf_ptr2len(src - 1); @@ -6866,7 +6866,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, s += l; len -= l; if (copy) - mb_char2bytes(cc, dst); + utf_char2bytes(cc, dst); dst += mb_char2len(cc) - 1; } else if (copy) *dst = cc; diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 3be1f3d2f3..5a33113af2 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -564,7 +564,7 @@ static char_u *nfa_get_match_text(nfa_state_T *start) s = ret; while (p->c > 0) { if (has_mbyte) - s += (*mb_char2bytes)(p->c, s); + s += utf_char2bytes(p->c, s); else *s++ = p->c; p = p->out; diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 884fef69d1..1967ef4773 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3539,7 +3539,7 @@ win_line ( xfree(p_extra_free); p_extra_free = p; for (i = 0; i < tab_len; i++) { - mb_char2bytes(lcs_tab2, p); + utf_char2bytes(lcs_tab2, p); p += mb_char2len(lcs_tab2); n_extra += mb_char2len(lcs_tab2) - (saved_nextra > 0 ? 1: 0); } @@ -5120,7 +5120,7 @@ win_redr_custom ( /* fill up with "fillchar" */ while (width < maxwidth && len < (int)sizeof(buf) - 1) { - len += (*mb_char2bytes)(fillchar, buf + len); + len += utf_char2bytes(fillchar, buf + len); ++width; } buf[len] = NUL; @@ -5229,7 +5229,7 @@ void screen_putchar(int c, int row, int col, int attr) { char_u buf[MB_MAXBYTES + 1]; - buf[(*mb_char2bytes)(c, buf)] = NUL; + buf[utf_char2bytes(c, buf)] = NUL; screen_puts(buf, row, col, attr); } @@ -6955,7 +6955,7 @@ static void win_redr_ruler(win_T *wp, int always) // Need at least 3 chars left for get_rel_pos() + NUL. while (this_ru_col + o < width && RULER_BUF_LEN > i + 4) { if (has_mbyte) - i += (*mb_char2bytes)(fillchar, buffer + i); + i += utf_char2bytes(fillchar, buffer + i); else buffer[i++] = fillchar; ++o; diff --git a/src/nvim/search.c b/src/nvim/search.c index 9280bb6fa4..34364b61c2 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1376,11 +1376,11 @@ int searchc(cmdarg_T *cap, int t_cmd) *lastc = c; set_csearch_direction(dir); set_csearch_until(t_cmd); - lastc_bytelen = (*mb_char2bytes)(c, lastc_bytes); + lastc_bytelen = utf_char2bytes(c, lastc_bytes); if (cap->ncharC1 != 0) { - lastc_bytelen += (*mb_char2bytes)(cap->ncharC1, lastc_bytes + lastc_bytelen); + lastc_bytelen += utf_char2bytes(cap->ncharC1, lastc_bytes + lastc_bytelen); if (cap->ncharC2 != 0) - lastc_bytelen += (*mb_char2bytes)(cap->ncharC2, lastc_bytes + lastc_bytelen); + lastc_bytelen += utf_char2bytes(cap->ncharC2, lastc_bytes + lastc_bytelen); } } } else { // repeat previous search diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 0ac1dd95e2..9a6f86d25e 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2684,7 +2684,7 @@ int spell_casefold(char_u *str, int len, char_u *buf, int buflen) return FAIL; } c = mb_cptr2char_adv((const char_u **)&p); - outi += mb_char2bytes(SPELL_TOFOLD(c), buf + outi); + outi += utf_char2bytes(SPELL_TOFOLD(c), buf + outi); } buf[outi] = NUL; } else { @@ -3434,7 +3434,7 @@ void onecap_copy(char_u *word, char_u *wcopy, bool upper) c = SPELL_TOFOLD(c); } if (has_mbyte) { - l = mb_char2bytes(c, wcopy); + l = utf_char2bytes(c, wcopy); } else { l = 1; wcopy[0] = c; @@ -3469,7 +3469,7 @@ static void allcap_copy(char_u *word, char_u *wcopy) if (has_mbyte) { if (d - wcopy >= MAXWLEN - MB_MAXBYTES) break; - d += mb_char2bytes(c, d); + d += utf_char2bytes(c, d); } else { if (d - wcopy >= MAXWLEN - 1) break; @@ -4546,7 +4546,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (has_mbyte) { fl = mb_char2len(c2); memmove(p, p + n, fl); - mb_char2bytes(c, p + fl); + utf_char2bytes(c, p + fl); stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; } else { p[0] = c2; @@ -4565,7 +4565,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so n = MB_PTR2LEN(p); c = utf_ptr2char(p + n); memmove(p + MB_PTR2LEN(p + n), p, n); - mb_char2bytes(c, p); + utf_char2bytes(c, p); // FALLTHROUGH @@ -4607,8 +4607,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (has_mbyte) { tl = mb_char2len(c3); memmove(p, p + n + fl, tl); - mb_char2bytes(c2, p + tl); - mb_char2bytes(c, p + fl + tl); + utf_char2bytes(c2, p + tl); + utf_char2bytes(c, p + fl + tl); stack[depth].ts_fidxtry = sp->ts_fidx + n + fl + tl; } else { p[0] = p[2]; @@ -4630,8 +4630,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so 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); + utf_char2bytes(c, p); + utf_char2bytes(c2, p + tl); p = p + tl; if (!soundfold && !spell_iswordp(p, curwin)) { @@ -4677,7 +4677,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so c = utf_ptr2char(p + n); tl = MB_PTR2LEN(p + n); memmove(p + tl, p, n); - mb_char2bytes(c, p); + utf_char2bytes(c, p); // Rotate three bytes right: "123" -> "312". We change "fword" // here, it's changed back afterwards at STATE_UNROT3R. @@ -4698,7 +4698,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so c = utf_ptr2char(p + n); tl = MB_CPTR2LEN(p + n); memmove(p + tl, p, n); - mb_char2bytes(c, p); + utf_char2bytes(c, p); stack[depth].ts_fidxtry = sp->ts_fidx + n + tl; } else { PROF_STORE(sp->ts_state) @@ -4714,7 +4714,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so n = MB_PTR2LEN(p + tl); n += MB_PTR2LEN(p + tl + n); memmove(p, p + tl, n); - mb_char2bytes(c, p + n); + utf_char2bytes(c, p + n); // FALLTHROUGH @@ -5539,7 +5539,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2) hashitem_T *hi; if (c1 >= 256) { - buf[mb_char2bytes(c1, buf)] = 0; + buf[utf_char2bytes(c1, buf)] = 0; hi = hash_find(&slang->sl_map_hash, buf); if (HASHITEM_EMPTY(hi)) { m1 = 0; @@ -5554,7 +5554,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2) } if (c2 >= 256) { - buf[mb_char2bytes(c2, buf)] = 0; + buf[utf_char2bytes(c2, buf)] = 0; hi = hash_find(&slang->sl_map_hash, buf); if (HASHITEM_EMPTY(hi)) { m2 = 0; @@ -5917,7 +5917,7 @@ static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) } if (c != NUL && c != prevc) { - ri += mb_char2bytes(c, res + ri); + ri += utf_char2bytes(c, res + ri); if (ri + MB_MAXBYTES > MAXWLEN) break; prevc = c; @@ -6440,7 +6440,7 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) // Convert wide characters in "wres" to a multi-byte string in "res". l = 0; for (n = 0; n < reslen; ++n) { - l += mb_char2bytes(wres[n], res + l); + l += utf_char2bytes(wres[n], res + l); if (l + MB_MAXBYTES > MAXWLEN) break; } diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 21a86c6946..d8538207af 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1460,7 +1460,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) if (c == '?' || c == '+' || c == '~') *pp++ = '\\'; // "a?" becomes "a\?", "a+" becomes "a\+" if (enc_utf8) - pp += mb_char2bytes(c, pp); + pp += utf_char2bytes(c, pp); else *pp++ = c; } @@ -4246,7 +4246,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) size_t l = 0; for (size_t i = 128; i < 256; ++i) { if (has_mbyte) - l += (size_t)mb_char2bytes(spelltab.st_fold[i], folchars + l); + l += (size_t)utf_char2bytes(spelltab.st_fold[i], folchars + l); else folchars[l++] = spelltab.st_fold[i]; } @@ -5710,9 +5710,9 @@ static void set_map_str(slang_T *lp, char_u *map) hashitem_T *hi; b = xmalloc(cl + headcl + 2); - mb_char2bytes(c, b); + utf_char2bytes(c, b); b[cl] = NUL; - mb_char2bytes(headc, b + cl + 1); + utf_char2bytes(headc, b + cl + 1); b[cl + 1 + headcl] = NUL; hash = hash_hash(b); hi = hash_lookup(&lp->sl_map_hash, (const char *)b, STRLEN(b), hash); -- cgit From ac13e65ae0ce98516e816ba4fcf468d19e750c30 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Sun, 2 Sep 2018 01:36:18 +0300 Subject: Remove has_mbytes local to lines changed in parent commit --- src/nvim/edit.c | 17 ++++------------- src/nvim/eval.c | 12 +++--------- src/nvim/ex_getln.c | 19 +++++-------------- src/nvim/getchar.c | 12 ++++-------- src/nvim/keymap.c | 8 +++----- src/nvim/ops.c | 9 ++------- src/nvim/regexp.c | 35 ++++++++++++++--------------------- src/nvim/regexp_nfa.c | 5 +---- src/nvim/screen.c | 5 +---- src/nvim/spell.c | 49 +++++++++++++------------------------------------ src/nvim/spellfile.c | 10 ++-------- 11 files changed, 52 insertions(+), 129 deletions(-) (limited to 'src') diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 908dd90cdb..414e2fd36c 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2131,11 +2131,7 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int char_u *p = IObuff; i = 0; while (i < actual_len && (p - IObuff + 6) < IOSIZE) { - if (has_mbyte) { - p += utf_char2bytes(wca[i++], p); - } else { - *(p++) = wca[i++]; - } + p += utf_char2bytes(wca[i++], p); } *p = NUL; } @@ -3084,7 +3080,7 @@ static void ins_compl_addleader(int c) if (stop_arrow() == FAIL) { return; } - if (has_mbyte && (cc = (*mb_char2len)(c)) > 1) { + if ((cc = utf_char2len(c)) > 1) { char_u buf[MB_MAXBYTES + 1]; utf_char2bytes(c, buf); @@ -5334,7 +5330,7 @@ insertchar ( } else { int cc; - if (has_mbyte && (cc = (*mb_char2len)(c)) > 1) { + if ((cc = utf_char2len(c)) > 1) { char_u buf[MB_MAXBYTES + 1]; utf_char2bytes(c, buf); @@ -8660,12 +8656,7 @@ static char_u *do_insert_char_pre(int c) if (!has_event(EVENT_INSERTCHARPRE)) { return NULL; } - if (has_mbyte) { - buf[utf_char2bytes(c, (char_u *) buf)] = NUL; - } else { - buf[0] = c; - buf[1] = NUL; - } + buf[utf_char2bytes(c, (char_u *) buf)] = NUL; // Lock the text to avoid weird things from happening. textlock++; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index b56032437b..0a84c26762 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9477,10 +9477,8 @@ static void f_getchar(typval_T *argvars, typval_T *rettv, FunPtr fptr) temp[i++] = K_SPECIAL; temp[i++] = K_SECOND(n); temp[i++] = K_THIRD(n); - } else if (has_mbyte) + } else i += utf_char2bytes(n, temp + i); - else - temp[i++] = n; temp[i++] = NUL; rettv->v_type = VAR_STRING; rettv->vval.v_string = vim_strsave(temp); @@ -18346,12 +18344,8 @@ void set_vim_var_char(int c) { char buf[MB_MAXBYTES + 1]; - if (has_mbyte) { - buf[utf_char2bytes(c, (char_u *) buf)] = NUL; - } else { - buf[0] = c; - buf[1] = NUL; - } + buf[utf_char2bytes(c, (char_u *) buf)] = NUL; + set_vim_var_string(VV_CHAR, buf, -1); } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index bfca888dc5..15308692e1 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1762,14 +1762,10 @@ static int command_line_handle_key(CommandLineState *s) if (IS_SPECIAL(s->c) || mod_mask != 0) { put_on_cmdline(get_special_key_name(s->c, mod_mask), -1, true); } else { - if (has_mbyte) { - s->j = utf_char2bytes(s->c, IObuff); - IObuff[s->j] = NUL; // exclude composing chars - put_on_cmdline(IObuff, s->j, true); - } else { - IObuff[0] = s->c; - put_on_cmdline(IObuff, 1, true); - } + s->j = utf_char2bytes(s->c, IObuff); + IObuff[s->j] = NUL; // exclude composing chars + put_on_cmdline(IObuff, s->j, true); + } return command_line_changed(s); } @@ -2372,12 +2368,7 @@ redraw: if (IS_SPECIAL(c1)) { c1 = '?'; } - if (has_mbyte) { - len = utf_char2bytes(c1, (char_u *)line_ga.ga_data + line_ga.ga_len); - } else { - len = 1; - ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; - } + len = utf_char2bytes(c1, (char_u *)line_ga.ga_data + line_ga.ga_len); if (c1 == '\n') msg_putchar('\n'); else if (c1 == TAB) { diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 544d518ff1..75d05fc891 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -3657,14 +3657,10 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) } else { if (c < ABBR_OFF && (c < ' ' || c > '~')) tb[j++] = Ctrl_V; /* special char needs CTRL-V */ - if (has_mbyte) { - /* if ABBR_OFF has been added, remove it here */ - if (c >= ABBR_OFF) - c -= ABBR_OFF; - j += utf_char2bytes(c, tb + j); - } else { - tb[j++] = (char_u)c; - } + /* if ABBR_OFF has been added, remove it here */ + if (c >= ABBR_OFF) + c -= ABBR_OFF; + j += utf_char2bytes(c, tb + j); } tb[j] = NUL; /* insert the last typed char */ diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index fad4722661..ea1e84452e 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -465,7 +465,7 @@ char_u *get_special_key_name(int c, int modifiers) } /* Not a special key, only modifiers, output directly */ else { - if (has_mbyte && (*mb_char2len)(c) > 1) + if (utf_char2len(c) > 1) idx += utf_char2bytes(c, string + idx); else if (vim_isprintc(c)) string[idx++] = (char_u)c; @@ -524,14 +524,12 @@ unsigned int trans_special(const char_u **srcp, const size_t src_len, dst[dlen++] = K_SPECIAL; dst[dlen++] = (char_u)KEY2TERMCAP0(key); dst[dlen++] = KEY2TERMCAP1(key); - } else if (has_mbyte && !keycode) { + } else if (!keycode) { dlen += (unsigned int)utf_char2bytes(key, dst + dlen); - } else if (keycode) { + } else { char_u *after = add_char2buf(key, dst + dlen); assert(after >= dst && (uintmax_t)(after - dst) <= UINT_MAX); dlen = (unsigned int)(after - dst); - } else { - dst[dlen++] = (char_u)key; } return dlen; diff --git a/src/nvim/ops.c b/src/nvim/ops.c index fcfadbfd28..d28e51ba4d 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1737,13 +1737,8 @@ int op_replace(oparg_T *oap, int c) if (had_ctrl_v_cr || (c != '\r' && c != '\n')) { // strlen(newp) at this point int newp_len = bd.textcol + bd.startspaces; - if (has_mbyte) { - while (--num_chars >= 0) { - newp_len += utf_char2bytes(c, newp + newp_len); - } - } else { - memset(newp + newp_len, c, (size_t)numc); - newp_len += numc; + while (--num_chars >= 0) { + newp_len += utf_char2bytes(c, newp + newp_len); } if (!bd.is_short) { // insert post-spaces diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 7152a38815..085b70ad7e 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -2538,10 +2538,8 @@ static void regc(int b) */ static void regmbc(int c) { - if (!has_mbyte && c > 0xff) - return; if (regcode == JUST_CALC_SIZE) - regsize += (*mb_char2len)(c); + regsize += utf_char2len(c); else regcode += utf_char2bytes(c, regcode); } @@ -6759,27 +6757,22 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, cc = c; } - if (has_mbyte) { - int totlen = mb_ptr2len(src - 1); + int totlen = utfc_ptr2len(src - 1); if (copy) utf_char2bytes(cc, dst); - dst += mb_char2len(cc) - 1; - if (enc_utf8) { - int clen = utf_ptr2len(src - 1); - - /* If the character length is shorter than "totlen", there - * are composing characters; copy them as-is. */ - if (clen < totlen) { - if (copy) - memmove(dst + 1, src - 1 + clen, - (size_t)(totlen - clen)); - dst += totlen - clen; - } + dst += utf_char2len(cc) - 1; + int clen = utf_ptr2len(src - 1); + + /* If the character length is shorter than "totlen", there + * are composing characters; copy them as-is. */ + if (clen < totlen) { + if (copy) + memmove(dst + 1, src - 1 + clen, + (size_t)(totlen - clen)); + dst += totlen - clen; } src += totlen - 1; - } else if (copy) - *dst = cc; dst++; } else { if (REG_MULTI) { @@ -6861,13 +6854,13 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, if (enc_utf8) l = utf_ptr2len(s) - 1; else - l = mb_ptr2len(s) - 1; + l = utfc_ptr2len(s) - 1; s += l; len -= l; if (copy) utf_char2bytes(cc, dst); - dst += mb_char2len(cc) - 1; + dst += utf_char2len(cc) - 1; } else if (copy) *dst = cc; dst++; diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 5a33113af2..5b58003047 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -563,10 +563,7 @@ static char_u *nfa_get_match_text(nfa_state_T *start) p = start->out->out; /* skip first char, it goes into regstart */ s = ret; while (p->c > 0) { - if (has_mbyte) - s += utf_char2bytes(p->c, s); - else - *s++ = p->c; + s += utf_char2bytes(p->c, s); p = p->out; } *s = NUL; diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 1967ef4773..63d8f5d506 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -6954,10 +6954,7 @@ static void win_redr_ruler(win_T *wp, int always) if (this_ru_col + o < width) { // Need at least 3 chars left for get_rel_pos() + NUL. while (this_ru_col + o < width && RULER_BUF_LEN > i + 4) { - if (has_mbyte) - i += utf_char2bytes(fillchar, buffer + i); - else - buffer[i++] = fillchar; + i += utf_char2bytes(fillchar, buffer + i); ++o; } get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 9a6f86d25e..92ded29a70 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -3433,12 +3433,7 @@ void onecap_copy(char_u *word, char_u *wcopy, bool upper) } else { c = SPELL_TOFOLD(c); } - if (has_mbyte) { - l = utf_char2bytes(c, wcopy); - } else { - l = 1; - wcopy[0] = c; - } + l = utf_char2bytes(c, wcopy); STRLCPY(wcopy + l, p, MAXWLEN - l); } @@ -3466,15 +3461,9 @@ static void allcap_copy(char_u *word, char_u *wcopy) } else c = SPELL_TOUPPER(c); - if (has_mbyte) { - if (d - wcopy >= MAXWLEN - MB_MAXBYTES) - break; - d += utf_char2bytes(c, d); - } else { - if (d - wcopy >= MAXWLEN - 1) - break; - *d++ = c; - } + if (d - wcopy >= MAXWLEN - MB_MAXBYTES) + break; + d += utf_char2bytes(c, d); } *d = NUL; } @@ -4543,16 +4532,10 @@ 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_UNSWAP; ++depth; - if (has_mbyte) { - fl = mb_char2len(c2); - memmove(p, p + n, fl); - utf_char2bytes(c, p + fl); - stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; - } else { - p[0] = c2; - p[1] = c; - stack[depth].ts_fidxtry = sp->ts_fidx + 2; - } + fl = mb_char2len(c2); + memmove(p, p + n, fl); + utf_char2bytes(c, p + fl); + stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; } else // If this swap doesn't work then SWAP3 won't either. PROF_STORE(sp->ts_state) @@ -4604,17 +4587,11 @@ 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_UNSWAP3; ++depth; - if (has_mbyte) { - tl = mb_char2len(c3); - memmove(p, p + n + fl, tl); - utf_char2bytes(c2, p + tl); - utf_char2bytes(c, p + fl + tl); - stack[depth].ts_fidxtry = sp->ts_fidx + n + fl + tl; - } else { - p[0] = p[2]; - p[2] = c; - stack[depth].ts_fidxtry = sp->ts_fidx + 3; - } + tl = mb_char2len(c3); + memmove(p, p + n + fl, tl); + utf_char2bytes(c2, p + tl); + utf_char2bytes(c, p + fl + tl); + stack[depth].ts_fidxtry = sp->ts_fidx + n + fl + tl; } else { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index d8538207af..cc9af6fd80 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1459,10 +1459,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) } else { // normal char, "[abc]" and '*' are copied as-is if (c == '?' || c == '+' || c == '~') *pp++ = '\\'; // "a?" becomes "a\?", "a+" becomes "a\+" - if (enc_utf8) - pp += utf_char2bytes(c, pp); - else - *pp++ = c; + pp += utf_char2bytes(c, pp); } } @@ -4245,10 +4242,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) // Form the string first, we need to know its length. size_t l = 0; for (size_t i = 128; i < 256; ++i) { - if (has_mbyte) - l += (size_t)utf_char2bytes(spelltab.st_fold[i], folchars + l); - else - folchars[l++] = spelltab.st_fold[i]; + l += (size_t)utf_char2bytes(spelltab.st_fold[i], folchars + l); } put_bytes(fd, 1 + 128 + 2 + l, 4); // -- cgit From 329cfc3303cffd5c9aad7b2ad7f4323354d68b0d Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Sun, 2 Sep 2018 02:14:47 +0300 Subject: lint: clean-up after parent commits --- src/nvim/edit.c | 2 +- src/nvim/eval.c | 11 ++++++----- src/nvim/ex_getln.c | 13 ++++++------- src/nvim/getchar.c | 10 ++++++---- src/nvim/keymap.c | 11 +++++------ src/nvim/regexp.c | 47 ++++++++++++++++++++++++----------------------- src/nvim/screen.c | 4 ++-- src/nvim/search.c | 9 ++++++--- src/nvim/spell.c | 18 +++++++++++------- src/nvim/spellfile.c | 5 +++-- 10 files changed, 70 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 414e2fd36c..e42fe4efb0 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -8656,7 +8656,7 @@ static char_u *do_insert_char_pre(int c) if (!has_event(EVENT_INSERTCHARPRE)) { return NULL; } - buf[utf_char2bytes(c, (char_u *) buf)] = NUL; + buf[utf_char2bytes(c, (char_u *)buf)] = NUL; // Lock the text to avoid weird things from happening. textlock++; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 0a84c26762..38a080b1ef 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4718,10 +4718,11 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) ++p; /* For "\u" store the number according to * 'encoding'. */ - if (c != 'X') + if (c != 'X') { name += utf_char2bytes(nr, name); - else + } else { *name++ = nr; + } } break; @@ -9477,8 +9478,9 @@ static void f_getchar(typval_T *argvars, typval_T *rettv, FunPtr fptr) temp[i++] = K_SPECIAL; temp[i++] = K_SECOND(n); temp[i++] = K_THIRD(n); - } else + } else { i += utf_char2bytes(n, temp + i); + } temp[i++] = NUL; rettv->v_type = VAR_STRING; rettv->vval.v_string = vim_strsave(temp); @@ -18344,8 +18346,7 @@ void set_vim_var_char(int c) { char buf[MB_MAXBYTES + 1]; - buf[utf_char2bytes(c, (char_u *) buf)] = NUL; - + buf[utf_char2bytes(c, (char_u *)buf)] = NUL; set_vim_var_string(VV_CHAR, buf, -1); } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 15308692e1..c2559e051d 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1765,7 +1765,6 @@ static int command_line_handle_key(CommandLineState *s) s->j = utf_char2bytes(s->c, IObuff); IObuff[s->j] = NUL; // exclude composing chars put_on_cmdline(IObuff, s->j, true); - } return command_line_changed(s); } @@ -2369,10 +2368,10 @@ redraw: c1 = '?'; } len = utf_char2bytes(c1, (char_u *)line_ga.ga_data + line_ga.ga_len); - if (c1 == '\n') + if (c1 == '\n') { msg_putchar('\n'); - else if (c1 == TAB) { - /* Don't use chartabsize(), 'ts' can be different */ + } else if (c1 == TAB) { + // Don't use chartabsize(), 'ts' can be different. do { msg_putchar(' '); } while (++vcol % 8); @@ -2891,9 +2890,9 @@ static void draw_cmdline(int start, int len) newlen += utf_char2bytes(u8c, arshape_buf + newlen); if (u8cc[0] != 0) { newlen += utf_char2bytes(u8cc[0], arshape_buf + newlen); - if (u8cc[1] != 0) - newlen += utf_char2bytes(u8cc[1], - arshape_buf + newlen); + if (u8cc[1] != 0) { + newlen += utf_char2bytes(u8cc[1], arshape_buf + newlen); + } } } else { prev_c = u8c; diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 75d05fc891..8f1e5bb6c1 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -3655,11 +3655,13 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) tb[j++] = (char_u)K_SECOND(c); tb[j++] = (char_u)K_THIRD(c); } else { - if (c < ABBR_OFF && (c < ' ' || c > '~')) - tb[j++] = Ctrl_V; /* special char needs CTRL-V */ - /* if ABBR_OFF has been added, remove it here */ - if (c >= ABBR_OFF) + if (c < ABBR_OFF && (c < ' ' || c > '~')) { + tb[j++] = Ctrl_V; // special char needs CTRL-V + } + // if ABBR_OFF has been added, remove it here. + if (c >= ABBR_OFF) { c -= ABBR_OFF; + } j += utf_char2bytes(c, tb + j); } tb[j] = NUL; diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index ea1e84452e..ade5487ec8 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -462,14 +462,13 @@ char_u *get_special_key_name(int c, int modifiers) string[idx++] = '_'; string[idx++] = (char_u)KEY2TERMCAP0(c); string[idx++] = KEY2TERMCAP1(c); - } - /* Not a special key, only modifiers, output directly */ - else { - if (utf_char2len(c) > 1) + } else { + // Not a special key, only modifiers, output directly. + if (utf_char2len(c) > 1) { idx += utf_char2bytes(c, string + idx); - else if (vim_isprintc(c)) + } else if (vim_isprintc(c)) { string[idx++] = (char_u)c; - else { + } else { s = transchar(c); while (*s) string[idx++] = *s++; diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 085b70ad7e..4f51a8b4cf 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -2538,10 +2538,11 @@ static void regc(int b) */ static void regmbc(int c) { - if (regcode == JUST_CALC_SIZE) + if (regcode == JUST_CALC_SIZE) { regsize += utf_char2len(c); - else + } else { regcode += utf_char2bytes(c, regcode); + } } /* @@ -6757,22 +6758,23 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, cc = c; } - int totlen = utfc_ptr2len(src - 1); + int totlen = utfc_ptr2len(src - 1); - if (copy) - utf_char2bytes(cc, dst); - dst += utf_char2len(cc) - 1; - int clen = utf_ptr2len(src - 1); + if (copy) { + utf_char2bytes(cc, dst); + } + dst += utf_char2len(cc) - 1; + int clen = utf_ptr2len(src - 1); - /* If the character length is shorter than "totlen", there - * are composing characters; copy them as-is. */ - if (clen < totlen) { - if (copy) - memmove(dst + 1, src - 1 + clen, - (size_t)(totlen - clen)); - dst += totlen - clen; + // If the character length is shorter than "totlen", there + // are composing characters; copy them as-is. + if (clen < totlen) { + if (copy) { + memmove(dst + 1, src - 1 + clen, (size_t)(totlen - clen)); } - src += totlen - 1; + dst += totlen - clen; + } + src += totlen - 1; dst++; } else { if (REG_MULTI) { @@ -6849,20 +6851,19 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, if (has_mbyte) { int l; - /* Copy composing characters separately, one - * at a time. */ - if (enc_utf8) - l = utf_ptr2len(s) - 1; - else - l = utfc_ptr2len(s) - 1; + // Copy composing characters separately, one + // at a time. + l = utf_ptr2len(s) - 1; s += l; len -= l; - if (copy) + if (copy) { utf_char2bytes(cc, dst); + } dst += utf_char2len(cc) - 1; - } else if (copy) + } else if (copy) { *dst = cc; + } dst++; } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 63d8f5d506..69c3d3067d 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -5121,7 +5121,7 @@ win_redr_custom ( /* fill up with "fillchar" */ while (width < maxwidth && len < (int)sizeof(buf) - 1) { len += utf_char2bytes(fillchar, buf + len); - ++width; + width++; } buf[len] = NUL; @@ -6955,7 +6955,7 @@ static void win_redr_ruler(win_T *wp, int always) // Need at least 3 chars left for get_rel_pos() + NUL. while (this_ru_col + o < width && RULER_BUF_LEN > i + 4) { i += utf_char2bytes(fillchar, buffer + i); - ++o; + o++; } get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); } diff --git a/src/nvim/search.c b/src/nvim/search.c index 34364b61c2..7e06f96b87 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1378,9 +1378,12 @@ int searchc(cmdarg_T *cap, int t_cmd) set_csearch_until(t_cmd); lastc_bytelen = utf_char2bytes(c, lastc_bytes); if (cap->ncharC1 != 0) { - lastc_bytelen += utf_char2bytes(cap->ncharC1, lastc_bytes + lastc_bytelen); - if (cap->ncharC2 != 0) - lastc_bytelen += utf_char2bytes(cap->ncharC2, lastc_bytes + lastc_bytelen); + lastc_bytelen += utf_char2bytes(cap->ncharC1, + lastc_bytes + lastc_bytelen); + if (cap->ncharC2 != 0) { + lastc_bytelen += utf_char2bytes(cap->ncharC2, + lastc_bytes + lastc_bytelen); + } } } } else { // repeat previous search diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 92ded29a70..970e50771d 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -3461,8 +3461,9 @@ static void allcap_copy(char_u *word, char_u *wcopy) } else c = SPELL_TOUPPER(c); - if (d - wcopy >= MAXWLEN - MB_MAXBYTES) + if (d - wcopy >= MAXWLEN - MB_MAXBYTES) { break; + } d += utf_char2bytes(c, d); } *d = NUL; @@ -4531,15 +4532,16 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so #endif PROF_STORE(sp->ts_state) sp->ts_state = STATE_UNSWAP; - ++depth; + depth++; fl = mb_char2len(c2); memmove(p, p + n, fl); utf_char2bytes(c, p + fl); stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; - } else + } else { // If this swap doesn't work then SWAP3 won't either. PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; + } break; case STATE_UNSWAP: @@ -4586,7 +4588,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so #endif PROF_STORE(sp->ts_state) sp->ts_state = STATE_UNSWAP3; - ++depth; + depth++; tl = mb_char2len(c3); memmove(p, p + n + fl, tl); utf_char2bytes(c2, p + tl); @@ -5895,8 +5897,9 @@ static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) if (c != NUL && c != prevc) { ri += utf_char2bytes(c, res + ri); - if (ri + MB_MAXBYTES > MAXWLEN) + if (ri + MB_MAXBYTES > MAXWLEN) { break; + } prevc = c; } } @@ -6416,10 +6419,11 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) // Convert wide characters in "wres" to a multi-byte string in "res". l = 0; - for (n = 0; n < reslen; ++n) { + for (n = 0; n < reslen; n++) { l += utf_char2bytes(wres[n], res + l); - if (l + MB_MAXBYTES > MAXWLEN) + if (l + MB_MAXBYTES > MAXWLEN) { break; + } } res[l] = NUL; } diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index cc9af6fd80..f52ae61534 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1457,8 +1457,9 @@ static int read_compound(FILE *fd, slang_T *slang, int len) *pp++ = '|'; atstart = 1; } else { // normal char, "[abc]" and '*' are copied as-is - if (c == '?' || c == '+' || c == '~') + if (c == '?' || c == '+' || c == '~') { *pp++ = '\\'; // "a?" becomes "a\?", "a+" becomes "a\+" + } pp += utf_char2bytes(c, pp); } } @@ -4241,7 +4242,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) // Form the string first, we need to know its length. size_t l = 0; - for (size_t i = 128; i < 256; ++i) { + for (size_t i = 128; i < 256; i++) { l += (size_t)utf_char2bytes(spelltab.st_fold[i], folchars + l); } put_bytes(fd, 1 + 128 + 2 + l, 4); // -- cgit