diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-11-12 02:01:07 -0500 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-11-12 18:12:05 -0500 |
commit | 93c18867a0e79bf71bffa9f8ce533f224d759ee5 (patch) | |
tree | 9f3e0ae576c36e8b361aea782e69ed6d6edb5b6b /src | |
parent | f494516ccdc3284bcafadf36703644750a4383e4 (diff) | |
download | rneovim-93c18867a0e79bf71bffa9f8ce533f224d759ee5.tar.gz rneovim-93c18867a0e79bf71bffa9f8ce533f224d759ee5.tar.bz2 rneovim-93c18867a0e79bf71bffa9f8ce533f224d759ee5.zip |
vim-patch:8.1.0810: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_MBYTE, part 4.
https://github.com/vim/vim/commit/264b74fa545edfb92c0d7d08a02c26331cc5b168
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/getchar.c | 181 | ||||
-rw-r--r-- | src/nvim/search.c | 60 | ||||
-rw-r--r-- | src/nvim/spell.c | 575 | ||||
-rw-r--r-- | src/nvim/spellfile.c | 210 | ||||
-rw-r--r-- | src/nvim/syntax.c | 6 | ||||
-rw-r--r-- | src/nvim/window.c | 6 |
6 files changed, 365 insertions, 673 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 456979be00..a5c81b2795 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -563,9 +563,7 @@ void AppendToRedobuffLit(const char_u *str, int len) // Handle a special or multibyte character. // Composing chars separately are handled separately. - const int c = (has_mbyte - ? mb_cptr2char_adv((const char_u **)&s) - : (uint8_t)(*s++)); + const int c = mb_cptr2char_adv((const char_u **)&s); if (c < ' ' || c == DEL || (*s == NUL && (c == '0' || c == '^'))) { add_char_buff(&redobuff, Ctrl_V); } @@ -684,15 +682,16 @@ static int read_redo(bool init, bool old_redo) if ((c = *p) == NUL) { return c; } - /* Reverse the conversion done by add_char_buff() */ - /* For a multi-byte character get all the bytes and return the - * converted character. */ - if (has_mbyte && (c != K_SPECIAL || p[1] == KS_SPECIAL)) + // Reverse the conversion done by add_char_buff() */ + // For a multi-byte character get all the bytes and return the + // converted character. + if (c != K_SPECIAL || p[1] == KS_SPECIAL) { n = MB_BYTE2LEN_CHECK(c); - else + } else { n = 1; - for (i = 0;; ++i) { - if (c == K_SPECIAL) { /* special key or escaped K_SPECIAL */ + } + for (i = 0;; i++) { + if (c == K_SPECIAL) { // special key or escaped K_SPECIAL c = TO_SPECIAL(p[1], p[2]); p += 2; } @@ -2161,14 +2160,11 @@ static int vgetorpeek(bool advance) col = vcol = curwin->w_wcol = 0; ptr = get_cursor_line_ptr(); while (col < curwin->w_cursor.col) { - if (!ascii_iswhite(ptr[col])) + if (!ascii_iswhite(ptr[col])) { curwin->w_wcol = vcol; - vcol += lbr_chartabsize(ptr, ptr + col, - (colnr_T)vcol); - if (has_mbyte) - col += (*mb_ptr2len)(ptr + col); - else - ++col; + } + vcol += lbr_chartabsize(ptr, ptr + col, (colnr_T)vcol); + col += utfc_ptr2len(ptr + col); } curwin->w_wrow = curwin->w_cline_row + curwin->w_wcol / curwin->w_width_inner; @@ -2813,33 +2809,23 @@ int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, // Otherwise we won't be able to find the start of it in a // vi-compatible way. // - if (has_mbyte) { - int first, last; - int same = -1; - - first = vim_iswordp(lhs); - last = first; - p = lhs + (*mb_ptr2len)(lhs); - n = 1; - while (p < lhs + len) { - n++; // nr of (multi-byte) chars - last = vim_iswordp(p); // type of last char - if (same == -1 && last != first) { - same = n - 1; // count of same char type - } - p += (*mb_ptr2len)(p); - } - if (last && n > 2 && same >= 0 && same < n - 1) { - retval = 1; - goto theend; + int same = -1; + + const int first = vim_iswordp(lhs); + int last = first; + p = lhs + utfc_ptr2len(lhs); + n = 1; + while (p < lhs + len) { + n++; // nr of (multi-byte) chars + last = vim_iswordp(p); // type of last char + if (same == -1 && last != first) { + same = n - 1; // count of same char type } - } else if (vim_iswordc(lhs[len - 1])) { // ends in keyword char - for (n = 0; n < len - 2; n++) { - if (vim_iswordc(lhs[n]) != vim_iswordc(lhs[len - 2])) { - retval = 1; - goto theend; - } - } // for + p += (*mb_ptr2len)(p); + } + if (last && n > 2 && same >= 0 && same < n - 1) { + retval = 1; + goto theend; } // An abbreviation cannot contain white space. for (n = 0; n < len; n++) { @@ -3700,25 +3686,23 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file) return count == 0 ? FAIL : OK; } -/* - * Check for an abbreviation. - * Cursor is at ptr[col]. - * When inserting, mincol is where insert started. - * For the command line, mincol is what is to be skipped over. - * "c" is the character typed before check_abbr was called. It may have - * ABBR_OFF added to avoid prepending a CTRL-V to it. - * - * Historic vi practice: The last character of an abbreviation must be an id - * character ([a-zA-Z0-9_]). The characters in front of it must be all id - * characters or all non-id characters. This allows for abbr. "#i" to - * "#include". - * - * Vim addition: Allow for abbreviations that end in a non-keyword character. - * Then there must be white space before the abbr. - * - * return TRUE if there is an abbreviation, FALSE if not - */ -int check_abbr(int c, char_u *ptr, int col, int mincol) +// Check for an abbreviation. +// Cursor is at ptr[col]. +// When inserting, mincol is where insert started. +// For the command line, mincol is what is to be skipped over. +// "c" is the character typed before check_abbr was called. It may have +// ABBR_OFF added to avoid prepending a CTRL-V to it. +// +// Historic vi practice: The last character of an abbreviation must be an id +// character ([a-zA-Z0-9_]). The characters in front of it must be all id +// characters or all non-id characters. This allows for abbr. "#i" to +// "#include". +// +// Vim addition: Allow for abbreviations that end in a non-keyword character. +// Then there must be white space before the abbr. +// +// Return true if there is an abbreviation, false if not. +bool check_abbr(int c, char_u *ptr, int col, int mincol) { int len; int scol; /* starting column of the abbr. */ @@ -3727,36 +3711,36 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) char_u tb[MB_MAXBYTES + 4]; mapblock_T *mp; mapblock_T *mp2; - int clen = 0; /* length in characters */ - int is_id = TRUE; - int vim_abbr; - - if (typebuf.tb_no_abbr_cnt) /* abbrev. are not recursive */ - return FALSE; + int clen = 0; // length in characters + bool is_id = true; - /* no remapping implies no abbreviation, except for CTRL-] */ - if ((KeyNoremap & (RM_NONE|RM_SCRIPT)) != 0 && c != Ctrl_RSB) - return FALSE; + if (typebuf.tb_no_abbr_cnt) { // abbrev. are not recursive + return false; + } - /* - * Check for word before the cursor: If it ends in a keyword char all - * chars before it must be keyword chars or non-keyword chars, but not - * white space. If it ends in a non-keyword char we accept any characters - * before it except white space. - */ - if (col == 0) /* cannot be an abbr. */ - return FALSE; + // no remapping implies no abbreviation, except for CTRL-] + if ((KeyNoremap & (RM_NONE|RM_SCRIPT)) != 0 && c != Ctrl_RSB) { + return false; + } - if (has_mbyte) { - char_u *p; + // Check for word before the cursor: If it ends in a keyword char all + // chars before it must be keyword chars or non-keyword chars, but not + // white space. If it ends in a non-keyword char we accept any characters + // before it except white space. + if (col == 0) { // cannot be an abbr. + return false; + } - p = mb_prevptr(ptr, ptr + col); - if (!vim_iswordp(p)) - vim_abbr = TRUE; /* Vim added abbr. */ - else { - vim_abbr = FALSE; /* vi compatible abbr. */ - if (p > ptr) + { + bool vim_abbr; + char_u *p = mb_prevptr(ptr, ptr + col); + if (!vim_iswordp(p)) { + vim_abbr = true; // Vim added abbr. + } else { + vim_abbr = false; // vi compatible abbr. + if (p > ptr) { is_id = vim_iswordp(mb_prevptr(ptr, p)); + } } clen = 1; while (p > ptr + mincol) { @@ -3768,17 +3752,6 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) ++clen; } scol = (int)(p - ptr); - } else { - if (!vim_iswordc(ptr[col - 1])) - vim_abbr = TRUE; /* Vim added abbr. */ - else { - vim_abbr = FALSE; /* vi compatible abbr. */ - if (col > 1) - is_id = vim_iswordc(ptr[col - 2]); - } - for (scol = col - 1; scol > 0 && !ascii_isspace(ptr[scol - 1]) - && (vim_abbr || is_id == vim_iswordc(ptr[scol - 1])); --scol) - ; } if (scol < mincol) @@ -3866,14 +3839,14 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) tb[0] = Ctrl_H; tb[1] = NUL; - if (has_mbyte) - len = clen; /* Delete characters instead of bytes */ - while (len-- > 0) /* delete the from string */ - (void)ins_typebuf(tb, 1, 0, TRUE, mp->m_silent); - return TRUE; + len = clen; // Delete characters instead of bytes + while (len-- > 0) { // delete the from string + (void)ins_typebuf(tb, 1, 0, true, mp->m_silent); + } + return true; } } - return FALSE; + return false; } /* diff --git a/src/nvim/search.c b/src/nvim/search.c index b25333c9fa..f979889540 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -218,14 +218,11 @@ char_u *reverse_text(char_u *s) FUNC_ATTR_NONNULL_RET size_t len = STRLEN(s); char_u *rev = xmalloc(len + 1); size_t rev_i = len; - for (size_t s_i = 0; s_i < len; ++s_i) { - if (has_mbyte) { - int mb_len = (*mb_ptr2len)(s + s_i); - rev_i -= mb_len; - memmove(rev + rev_i, s + s_i, mb_len); - s_i += mb_len - 1; - } else - rev[--rev_i] = s[s_i]; + for (size_t s_i = 0; s_i < len; s_i++) { + const int mb_len = utfc_ptr2len(s + s_i); + rev_i -= mb_len; + memmove(rev + rev_i, s + s_i, mb_len); + s_i += mb_len - 1; } rev[len] = NUL; @@ -594,8 +591,8 @@ int searchit( // is zero. if (pos->col == MAXCOL) { start_char_len = 0; - } else if (has_mbyte - && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count + } else if (pos->lnum >= 1 + && pos->lnum <= buf->b_ml.ml_line_count && pos->col < MAXCOL - 2) { // Watch out for the "col" being MAXCOL - 2, used in a closed fold. ptr = ml_get_buf(buf, pos->lnum, false); @@ -1553,34 +1550,26 @@ int searchc(cmdarg_T *cap, int t_cmd) len = (int)STRLEN(p); while (count--) { - if (has_mbyte) { - for (;; ) { - if (dir > 0) { - col += (*mb_ptr2len)(p + col); - if (col >= len) - return FAIL; - } else { - if (col == 0) - return FAIL; - col -= utf_head_off(p, p + col - 1) + 1; + for (;; ) { + if (dir > 0) { + col += utfc_ptr2len(p + col); + if (col >= len) { + return FAIL; } - if (lastc_bytelen == 1) { - if (p[col] == c && stop) { - break; - } - } else if (STRNCMP(p + col, lastc_bytes, lastc_bytelen) == 0 && stop) { - break; + } else { + if (col == 0) { + return FAIL; } - stop = true; + col -= utf_head_off(p, p + col - 1) + 1; } - } else { - for (;; ) { - if ((col += dir) < 0 || col >= len) - return FAIL; - if (p[col] == c && stop) + if (lastc_bytelen == 1) { + if (p[col] == c && stop) { break; - stop = TRUE; + } + } else if (STRNCMP(p + col, lastc_bytes, lastc_bytelen) == 0 && stop) { + break; } + stop = true; } } @@ -1964,10 +1953,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) if (lisp) /* find comment pos in new line */ comment_col = check_linecomment(linep); } else { - if (has_mbyte) - pos.col += (*mb_ptr2len)(linep + pos.col); - else - ++pos.col; + pos.col += utfc_ptr2len(linep + pos.col); } } diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 636c71657d..797fe41320 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -513,10 +513,7 @@ size_t spell_check( } } - if (has_mbyte) { - return (size_t)(*mb_ptr2len)(ptr); - } - return 1; + return (size_t)(utfc_ptr2len(ptr)); } else if (mi.mi_end == ptr) { // Always include at least one character. Required for when there // is a mixup in "midword". @@ -722,7 +719,7 @@ static void find_word(matchinf_T *mip, int mode) // has been found we try compound flags. bool prefix_found = false; - if (mode != FIND_KEEPWORD && has_mbyte) { + if (mode != FIND_KEEPWORD) { // Compute byte length in original word, length may change // when folding case. This can be slow, take a shortcut when the // case-folded word is equal to the keep-case word. @@ -796,11 +793,11 @@ static void find_word(matchinf_T *mip, int mode) continue; // For multi-byte chars check character length against // COMPOUNDMIN. - if (has_mbyte - && slang->sl_compminlen > 0 + if (slang->sl_compminlen > 0 && mb_charlen_len(mip->mi_word + mip->mi_compoff, - wlen - mip->mi_compoff) < slang->sl_compminlen) + wlen - mip->mi_compoff) < slang->sl_compminlen) { continue; + } // Limit the number of compound words to COMPOUNDWORDMAX if no // maximum for syllables is specified. @@ -833,8 +830,7 @@ static void find_word(matchinf_T *mip, int mode) // Need to check the caps type of the appended compound // word. - if (has_mbyte && STRNCMP(ptr, mip->mi_word, - mip->mi_compoff) != 0) { + if (STRNCMP(ptr, mip->mi_word, mip->mi_compoff) != 0) { // case folding may have changed the length p = mip->mi_word; for (char_u *s = ptr; s < ptr + mip->mi_compoff; MB_PTR_ADV(s)) { @@ -907,7 +903,7 @@ static void find_word(matchinf_T *mip, int mode) // Find following word in case-folded tree. mip->mi_compoff = endlen[endidxcnt]; - if (has_mbyte && mode == FIND_KEEPWORD) { + if (mode == FIND_KEEPWORD) { // Compute byte length in case-folded word from "wlen": // byte length in keep-case word. Length may change when // folding case. This can be slow, take a shortcut when @@ -1260,12 +1256,9 @@ static void find_prefix(matchinf_T *mip, int mode) // Skip over the previously found word(s). mip->mi_prefixlen += mip->mi_compoff; - if (has_mbyte) { - // Case-folded length may differ from original length. - mip->mi_cprefixlen = nofold_len(mip->mi_fword, - mip->mi_prefixlen, mip->mi_word); - } else - mip->mi_cprefixlen = mip->mi_prefixlen; + // Case-folded length may differ from original length. + mip->mi_cprefixlen = nofold_len(mip->mi_fword, mip->mi_prefixlen, + mip->mi_word); find_word(mip, FIND_PREFIX); @@ -2272,35 +2265,30 @@ static void clear_midword(win_T *wp) // Use the "sl_midword" field of language "lp" for buffer "buf". // They add up to any currently used midword characters. static void use_midword(slang_T *lp, win_T *wp) + FUNC_ATTR_NONNULL_ALL { - char_u *p; - - if (lp->sl_midword == NULL) // there aren't any + if (lp->sl_midword == NULL) { // there aren't any return; + } - for (p = lp->sl_midword; *p != NUL; ) - if (has_mbyte) { - int c, l, n; - char_u *bp; - - c = utf_ptr2char(p); - l = (*mb_ptr2len)(p); - if (c < 256 && l <= 2) - wp->w_s->b_spell_ismw[c] = true; - else if (wp->w_s->b_spell_ismw_mb == NULL) - // First multi-byte char in "b_spell_ismw_mb". - wp->w_s->b_spell_ismw_mb = vim_strnsave(p, l); - else { - // Append multi-byte chars to "b_spell_ismw_mb". - n = (int)STRLEN(wp->w_s->b_spell_ismw_mb); - bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l); - xfree(wp->w_s->b_spell_ismw_mb); - wp->w_s->b_spell_ismw_mb = bp; - STRLCPY(bp + n, p, l + 1); - } - p += l; - } else - wp->w_s->b_spell_ismw[*p++] = true; + for (char_u *p = lp->sl_midword; *p != NUL; ) { + const int c = utf_ptr2char(p); + const int l = utfc_ptr2len(p); + if (c < 256 && l <= 2) { + wp->w_s->b_spell_ismw[c] = true; + } else if (wp->w_s->b_spell_ismw_mb == NULL) { + // First multi-byte char in "b_spell_ismw_mb". + wp->w_s->b_spell_ismw_mb = vim_strnsave(p, l); + } else { + // Append multi-byte chars to "b_spell_ismw_mb". + const int n = (int)STRLEN(wp->w_s->b_spell_ismw_mb); + char_u *bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l); + xfree(wp->w_s->b_spell_ismw_mb); + wp->w_s->b_spell_ismw_mb = bp; + STRLCPY(bp + n, p, l + 1); + } + p += l; + } } // Find the region "region[2]" in "rp" (points to "sl_regions"). @@ -2333,7 +2321,6 @@ int captype(char_u *word, char_u *end) FUNC_ATTR_NONNULL_ARG(1) { char_u *p; - int c; int firstcap; bool allcap; bool past_second = false; // past second word char @@ -2344,11 +2331,7 @@ int captype(char_u *word, char_u *end) return 0; // only non-word characters, illegal word } } - if (has_mbyte) { - c = mb_ptr2char_adv((const char_u **)&p); - } else { - c = *p++; - } + int c = mb_ptr2char_adv((const char_u **)&p); firstcap = allcap = SPELL_ISUPPER(c); // Need to check all letters to find a word with mixed upper/lower. @@ -2673,34 +2656,23 @@ static bool spell_iswordp_w(const int *p, const win_T *wp) // Returns FAIL when something wrong. int spell_casefold(char_u *str, int len, char_u *buf, int buflen) { - int i; - if (len >= buflen) { buf[0] = NUL; return FAIL; // result will not fit } - if (has_mbyte) { - int outi = 0; - char_u *p; - int c; + int outi = 0; - // Fold one character at a time. - for (p = str; p < str + len; ) { - if (outi + MB_MAXBYTES > buflen) { - buf[outi] = NUL; - return FAIL; - } - c = mb_cptr2char_adv((const char_u **)&p); - outi += utf_char2bytes(SPELL_TOFOLD(c), buf + outi); + // Fold one character at a time. + for (char_u *p = str; p < str + len; ) { + if (outi + MB_MAXBYTES > buflen) { + buf[outi] = NUL; + return FAIL; } - buf[outi] = NUL; - } else { - // Be quick for non-multibyte encodings. - for (i = 0; i < len; ++i) - buf[i] = spelltab.st_fold[str[i]]; - buf[i] = NUL; + const int c = mb_cptr2char_adv((const char_u **)&p); + outi += utf_char2bytes(SPELL_TOFOLD(c), buf + outi); } + buf[outi] = NUL; return OK; } @@ -3428,22 +3400,14 @@ static void spell_find_cleanup(suginfo_T *su) /// @param[in] upper True to upper case, otherwise lower case void onecap_copy(char_u *word, char_u *wcopy, bool upper) { - char_u *p; - int c; - int l; - - p = word; - if (has_mbyte) { - c = mb_cptr2char_adv((const char_u **)&p); - } else { - c = *p++; - } + char_u *p = word; + int c = mb_cptr2char_adv((const char_u **)&p); if (upper) { c = SPELL_TOUPPER(c); } else { c = SPELL_TOFOLD(c); } - l = utf_char2bytes(c, wcopy); + int l = utf_char2bytes(c, wcopy); STRLCPY(wcopy + l, p, MAXWLEN - l); } @@ -3451,17 +3415,9 @@ void onecap_copy(char_u *word, char_u *wcopy, bool upper) // "wcopy[MAXWLEN]". The result is NUL terminated. static void allcap_copy(char_u *word, char_u *wcopy) { - char_u *s; - char_u *d; - int c; - - d = wcopy; - for (s = word; *s != NUL; ) { - if (has_mbyte) { - c = mb_cptr2char_adv((const char_u **)&s); - } else { - c = *s++; - } + char_u *d = wcopy; + for (char_u *s = word; *s != NUL; ) { + int c = mb_cptr2char_adv((const char_u **)&s); if (c == 0xdf) { c = 'S'; @@ -3730,10 +3686,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (byts[arridx] == 0 || n == (int)STATE_NOPREFIX) { // Set su->su_badflags to the caps type at this position. // Use the caps type until here for the prefix itself. - if (has_mbyte) - n = nofold_len(fword, sp->ts_fidx, su->su_badptr); - else - n = sp->ts_fidx; + n = nofold_len(fword, sp->ts_fidx, su->su_badptr); flags = badword_captype(su->su_badptr, su->su_badptr + n); su->su_badflags = badword_captype(su->su_badptr + n, su->su_badptr + su->su_badlen); @@ -3851,15 +3804,16 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // flag). if (((unsigned)flags >> 24) == 0 || sp->ts_twordlen - sp->ts_splitoff - < slang->sl_compminlen) + < slang->sl_compminlen) { break; + } // For multi-byte chars check character length against // COMPOUNDMIN. - if (has_mbyte - && slang->sl_compminlen > 0 + if (slang->sl_compminlen > 0 && mb_charlen(tword + sp->ts_splitoff) - < slang->sl_compminlen) + < slang->sl_compminlen) { break; + } compflags[sp->ts_complen] = ((unsigned)flags >> 24); compflags[sp->ts_complen + 1] = NUL; @@ -4014,7 +3968,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Try word split and/or compounding. if ((sp->ts_fidx >= sp->ts_fidxtry || fword_ends) // Don't split in the middle of a character - && (!has_mbyte || sp->ts_tcharlen == 0) + && (sp->ts_tcharlen == 0) ) { bool try_compound; int try_split; @@ -4046,8 +4000,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so && ((unsigned)flags >> 24) != 0 && sp->ts_twordlen - sp->ts_splitoff >= slang->sl_compminlen - && (!has_mbyte - || slang->sl_compminlen == 0 + && (slang->sl_compminlen == 0 || mb_charlen(tword + sp->ts_splitoff) >= slang->sl_compminlen) && (slang->sl_compsylmax < MAXWLEN @@ -4166,10 +4119,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // set su->su_badflags to the caps type at this // position - if (has_mbyte) - n = nofold_len(fword, sp->ts_fidx, su->su_badptr); - else - n = sp->ts_fidx; + n = nofold_len(fword, sp->ts_fidx, su->su_badptr); su->su_badflags = badword_captype(su->su_badptr + n, su->su_badptr + su->su_badlen); @@ -4266,84 +4216,74 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so ++sp->ts_fidx; tword[sp->ts_twordlen++] = c; sp->ts_arridx = idxs[arridx]; - if (newscore == SCORE_SUBST) + if (newscore == SCORE_SUBST) { sp->ts_isdiff = DIFF_YES; - if (has_mbyte) { - // Multi-byte characters are a bit complicated to - // handle: They differ when any of the bytes differ - // and then their length may also differ. - if (sp->ts_tcharlen == 0) { - // First byte. - sp->ts_tcharidx = 0; - sp->ts_tcharlen = MB_BYTE2LEN(c); - sp->ts_fcharstart = sp->ts_fidx - 1; - sp->ts_isdiff = (newscore != 0) - ? DIFF_YES : DIFF_NONE; - } else if (sp->ts_isdiff == DIFF_INSERT) - // When inserting trail bytes don't advance in the - // bad word. - --sp->ts_fidx; - if (++sp->ts_tcharidx == sp->ts_tcharlen) { - // Last byte of character. - if (sp->ts_isdiff == DIFF_YES) { - // Correct ts_fidx for the byte length of the - // character (we didn't check that before). - sp->ts_fidx = sp->ts_fcharstart - + utfc_ptr2len(fword + sp->ts_fcharstart); - - // For changing a composing character adjust - // the score from SCORE_SUBST to - // SCORE_SUBCOMP. - if (utf_iscomposing(utf_ptr2char(tword + sp->ts_twordlen - - sp->ts_tcharlen)) - && 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))) { - // For a similar character adjust score from - // SCORE_SUBST to SCORE_SIMILAR. - sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR; - } - } else if (sp->ts_isdiff == DIFF_INSERT - && sp->ts_twordlen > sp->ts_tcharlen) { - p = tword + sp->ts_twordlen - sp->ts_tcharlen; - c = utf_ptr2char(p); - if (utf_iscomposing(c)) { - // Inserting a composing char doesn't - // count that much. - sp->ts_score -= SCORE_INS - SCORE_INSCOMP; - } else { - // If the previous character was the same, - // thus doubling a character, give a bonus - // to the score. Also for the soundfold - // tree (might seem illogical but does - // give better scores). - MB_PTR_BACK(tword, p); - if (c == utf_ptr2char(p)) { - sp->ts_score -= SCORE_INS - SCORE_INSDUP; - } + } + // Multi-byte characters are a bit complicated to + // handle: They differ when any of the bytes differ + // and then their length may also differ. + if (sp->ts_tcharlen == 0) { + // First byte. + sp->ts_tcharidx = 0; + sp->ts_tcharlen = MB_BYTE2LEN(c); + sp->ts_fcharstart = sp->ts_fidx - 1; + sp->ts_isdiff = (newscore != 0) + ? DIFF_YES : DIFF_NONE; + } else if (sp->ts_isdiff == DIFF_INSERT) { + // When inserting trail bytes don't advance in the + // bad word. + sp->ts_fidx--; + } + if (++sp->ts_tcharidx == sp->ts_tcharlen) { + // Last byte of character. + if (sp->ts_isdiff == DIFF_YES) { + // Correct ts_fidx for the byte length of the + // character (we didn't check that before). + sp->ts_fidx = sp->ts_fcharstart + + utfc_ptr2len(fword + sp->ts_fcharstart); + + // For changing a composing character adjust + // the score from SCORE_SUBST to + // SCORE_SUBCOMP. + if (utf_iscomposing(utf_ptr2char(tword + sp->ts_twordlen + - sp->ts_tcharlen)) + && 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))) { + // For a similar character adjust score from + // SCORE_SUBST to SCORE_SIMILAR. + sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR; + } + } else if (sp->ts_isdiff == DIFF_INSERT + && sp->ts_twordlen > sp->ts_tcharlen) { + p = tword + sp->ts_twordlen - sp->ts_tcharlen; + c = utf_ptr2char(p); + if (utf_iscomposing(c)) { + // Inserting a composing char doesn't + // count that much. + sp->ts_score -= SCORE_INS - SCORE_INSCOMP; + } else { + // If the previous character was the same, + // thus doubling a character, give a bonus + // to the score. Also for the soundfold + // tree (might seem illogical but does + // give better scores). + MB_PTR_BACK(tword, p); + if (c == utf_ptr2char(p)) { + sp->ts_score -= SCORE_INS - SCORE_INSDUP; } } - - // Starting a new char, reset the length. - sp->ts_tcharlen = 0; } - } else { - // If we found a similar char adjust the score. - // We do this after calling go_deeper() because - // it's slow. - if (newscore != 0 - && !soundfold - && slang->sl_has_map - && similar_chars(slang, - c, fword[sp->ts_fidx - 1])) - sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR; + + // Starting a new char, reset the length. + sp->ts_tcharlen = 0; } } } @@ -4352,7 +4292,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_DEL: // When past the first byte of a multi-byte char don't try // delete/insert/swap a character. - if (has_mbyte && sp->ts_tcharlen > 0) { + if (sp->ts_tcharlen > 0) { PROF_STORE(sp->ts_state) sp->ts_state = STATE_FINAL; break; @@ -4461,18 +4401,15 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so sp = &stack[depth]; tword[sp->ts_twordlen++] = c; sp->ts_arridx = idxs[n]; - if (has_mbyte) { - fl = MB_BYTE2LEN(c); - if (fl > 1) { - // There are following bytes for the same character. - // We must find all bytes before trying - // delete/insert/swap/etc. - sp->ts_tcharlen = fl; - sp->ts_tcharidx = 1; - sp->ts_isdiff = DIFF_INSERT; - } - } else - fl = 1; + fl = MB_BYTE2LEN(c); + if (fl > 1) { + // There are following bytes for the same character. + // We must find all bytes before trying + // delete/insert/swap/etc. + sp->ts_tcharlen = fl; + sp->ts_tcharidx = 1; + sp->ts_isdiff = DIFF_INSERT; + } if (fl == 1) { // If the previous character was the same, thus doubling a // character, give a bonus to the score. Also for @@ -4914,12 +4851,8 @@ static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) } else { // round[depth] == 1: Try using the folded-case character. // round[depth] == 2: Try using the upper-case character. - if (has_mbyte) { - flen = MB_CPTR2LEN(fword + fwordidx[depth]); - ulen = MB_CPTR2LEN(uword + uwordidx[depth]); - } else { - ulen = flen = 1; - } + flen = MB_CPTR2LEN(fword + fwordidx[depth]); + ulen = MB_CPTR2LEN(uword + uwordidx[depth]); if (round[depth] == 1) { p = fword + fwordidx[depth]; l = flen; @@ -5872,57 +5805,43 @@ void spell_soundfold(slang_T *slang, char_u *inword, bool folded, char_u *res) // SOFOTO lines. static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) { - char_u *s; int ri = 0; - int c; - if (has_mbyte) { - int prevc = 0; - int *ip; + int prevc = 0; - // The sl_sal_first[] table contains the translation for chars up to - // 255, sl_sal the rest. - for (s = inword; *s != NUL; ) { - c = mb_cptr2char_adv((const char_u **)&s); - if (utf_class(c) == 0) { - c = ' '; - } else if (c < 256) { - c = slang->sl_sal_first[c]; + // The sl_sal_first[] table contains the translation for chars up to + // 255, sl_sal the rest. + for (char_u *s = inword; *s != NUL; ) { + int c = mb_cptr2char_adv((const char_u **)&s); + if (utf_class(c) == 0) { + c = ' '; + } else if (c < 256) { + c = slang->sl_sal_first[c]; + } else { + int *ip = ((int **)slang->sl_sal.ga_data)[c & 0xff]; + if (ip == NULL) { // empty list, can't match + c = NUL; } else { - ip = ((int **)slang->sl_sal.ga_data)[c & 0xff]; - if (ip == NULL) // empty list, can't match - c = NUL; - else - for (;; ) { // find "c" in the list - if (*ip == 0) { // not found - c = NUL; - break; - } - if (*ip == c) { // match! - c = ip[1]; - break; - } - ip += 2; + for (;; ) { // find "c" in the list + if (*ip == 0) { // not found + c = NUL; + break; } - } - - if (c != NUL && c != prevc) { - ri += utf_char2bytes(c, res + ri); - if (ri + MB_MAXBYTES > MAXWLEN) { - break; + if (*ip == c) { // match! + c = ip[1]; + break; + } + ip += 2; } - prevc = c; } } - } else { - // The sl_sal_first[] table contains the translation. - for (s = inword; (c = *s) != NUL; ++s) { - if (ascii_iswhite(c)) - c = ' '; - else - c = slang->sl_sal_first[c]; - if (c != NUL && (ri == 0 || res[ri - 1] != c)) - res[ri++] = c; + + if (c != NUL && c != prevc) { + ri += utf_char2bytes(c, res + ri); + if (ri + MB_MAXBYTES > MAXWLEN) { + break; + } + prevc = c; } } @@ -6425,12 +6344,11 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword) int pbc, pgc; int wbadword[MAXWLEN]; int wgoodword[MAXWLEN]; - const bool l_has_mbyte = has_mbyte; // Lengths with NUL. int badlen; int goodlen; - if (l_has_mbyte) { + { // Get the characters from the multi-byte strings and put them in an // int array for easy access. badlen = 0; @@ -6443,9 +6361,6 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword) wgoodword[goodlen++] = mb_cptr2char_adv(&p); } wgoodword[goodlen++] = 0; - } else { - badlen = (int)STRLEN(badword) + 1; - goodlen = (int)STRLEN(goodword) + 1; } // We use "cnt" as an array: CNT(badword_idx, goodword_idx). @@ -6458,17 +6373,12 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword) for (i = 1; i <= badlen; ++i) { CNT(i, 0) = CNT(i - 1, 0) + SCORE_DEL; - for (j = 1; j <= goodlen; ++j) { - if (l_has_mbyte) { - bc = wbadword[i - 1]; - gc = wgoodword[j - 1]; - } else { - bc = badword[i - 1]; - gc = goodword[j - 1]; - } - if (bc == gc) + for (j = 1; j <= goodlen; j++) { + bc = wbadword[i - 1]; + gc = wgoodword[j - 1]; + if (bc == gc) { CNT(i, j) = CNT(i - 1, j - 1); - else { + } else { // Use a better score when there is only a case difference. if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc)) CNT(i, j) = SCORE_ICASE + CNT(i - 1, j - 1); @@ -6483,13 +6393,8 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword) } if (i > 1 && j > 1) { - if (l_has_mbyte) { - pbc = wbadword[i - 2]; - pgc = wgoodword[j - 2]; - } else { - pbc = badword[i - 2]; - pgc = goodword[j - 2]; - } + pbc = wbadword[i - 2]; + pgc = wgoodword[j - 2]; if (bc == pgc && pbc == gc) { t = SCORE_SWAP + CNT(i - 2, j - 2); if (t < CNT(i, j)) @@ -6519,147 +6424,7 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword) // for multi-byte characters. static int spell_edit_score_limit(slang_T *slang, char_u *badword, char_u *goodword, int limit) { - limitscore_T stack[10]; // allow for over 3 * 2 edits - int stackidx; - int bi, gi; - int bi2, gi2; - int bc, gc; - int score; - int score_off; - int minscore; - int round; - - // Multi-byte characters require a bit more work, use a different function - // to avoid testing "has_mbyte" quite often. - if (has_mbyte) - return spell_edit_score_limit_w(slang, badword, goodword, limit); - - // The idea is to go from start to end over the words. So long as - // characters are equal just continue, this always gives the lowest score. - // When there is a difference try several alternatives. Each alternative - // increases "score" for the edit distance. Some of the alternatives are - // pushed unto a stack and tried later, some are tried right away. At the - // end of the word the score for one alternative is known. The lowest - // possible score is stored in "minscore". - stackidx = 0; - bi = 0; - gi = 0; - score = 0; - minscore = limit + 1; - - for (;; ) { - // Skip over an equal part, score remains the same. - for (;; ) { - bc = badword[bi]; - gc = goodword[gi]; - if (bc != gc) // stop at a char that's different - break; - if (bc == NUL) { // both words end - if (score < minscore) - minscore = score; - goto pop; // do next alternative - } - ++bi; - ++gi; - } - - if (gc == NUL) { // goodword ends, delete badword chars - do { - if ((score += SCORE_DEL) >= minscore) - goto pop; // do next alternative - } while (badword[++bi] != NUL); - minscore = score; - } else if (bc == NUL) { // badword ends, insert badword chars - do { - if ((score += SCORE_INS) >= minscore) - goto pop; // do next alternative - } while (goodword[++gi] != NUL); - minscore = score; - } else { // both words continue - // If not close to the limit, perform a change. Only try changes - // that may lead to a lower score than "minscore". - // round 0: try deleting a char from badword - // round 1: try inserting a char in badword - for (round = 0; round <= 1; ++round) { - score_off = score + (round == 0 ? SCORE_DEL : SCORE_INS); - if (score_off < minscore) { - if (score_off + SCORE_EDIT_MIN >= minscore) { - // Near the limit, rest of the words must match. We - // can check that right now, no need to push an item - // onto the stack. - bi2 = bi + 1 - round; - gi2 = gi + round; - while (goodword[gi2] == badword[bi2]) { - if (goodword[gi2] == NUL) { - minscore = score_off; - break; - } - ++bi2; - ++gi2; - } - } else { - // try deleting/inserting a character later - stack[stackidx].badi = bi + 1 - round; - stack[stackidx].goodi = gi + round; - stack[stackidx].score = score_off; - ++stackidx; - } - } - } - - if (score + SCORE_SWAP < minscore) { - // If swapping two characters makes a match then the - // substitution is more expensive, thus there is no need to - // try both. - if (gc == badword[bi + 1] && bc == goodword[gi + 1]) { - // Swap two characters, that is: skip them. - gi += 2; - bi += 2; - score += SCORE_SWAP; - continue; - } - } - - // Substitute one character for another which is the same - // thing as deleting a character from both goodword and badword. - // Use a better score when there is only a case difference. - if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc)) - score += SCORE_ICASE; - else { - // For a similar character use SCORE_SIMILAR. - if (slang != NULL - && slang->sl_has_map - && similar_chars(slang, gc, bc)) - score += SCORE_SIMILAR; - else - score += SCORE_SUBST; - } - - if (score < minscore) { - // Do the substitution. - ++gi; - ++bi; - continue; - } - } -pop: - // Get here to try the next alternative, pop it from the stack. - if (stackidx == 0) // stack is empty, finished - break; - - // pop an item from the stack - --stackidx; - gi = stack[stackidx].goodi; - bi = stack[stackidx].badi; - score = stack[stackidx].score; - } - - // When the score goes over "limit" it may actually be much higher. - // Return a very large number to avoid going below the limit when giving a - // bonus. - if (minscore > limit) - return SCORE_MAXMAX; - return minscore; + return spell_edit_score_limit_w(slang, badword, goodword, limit); } // Multi-byte version of spell_edit_score_limit(). diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index b415a4635b..90af010164 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1221,18 +1221,18 @@ static int read_sal_section(FILE *fd, slang_T *slang) return ccnt; } - if (has_mbyte) { - // convert the multi-byte strings to wide char strings - smp->sm_lead_w = mb_str2wide(smp->sm_lead); - smp->sm_leadlen = mb_charlen(smp->sm_lead); - if (smp->sm_oneof == NULL) - smp->sm_oneof_w = NULL; - else - smp->sm_oneof_w = mb_str2wide(smp->sm_oneof); - if (smp->sm_to == NULL) - smp->sm_to_w = NULL; - else - smp->sm_to_w = mb_str2wide(smp->sm_to); + // convert the multi-byte strings to wide char strings + smp->sm_lead_w = mb_str2wide(smp->sm_lead); + smp->sm_leadlen = mb_charlen(smp->sm_lead); + if (smp->sm_oneof == NULL) { + smp->sm_oneof_w = NULL; + } else { + smp->sm_oneof_w = mb_str2wide(smp->sm_oneof); + } + if (smp->sm_to == NULL) { + smp->sm_to_w = NULL; + } else { + smp->sm_to_w = mb_str2wide(smp->sm_to); } } @@ -1488,72 +1488,61 @@ static int read_compound(FILE *fd, slang_T *slang, int len) // Returns SP_*ERROR flags when there is something wrong. static int set_sofo(slang_T *lp, char_u *from, char_u *to) { - int i; - - garray_T *gap; char_u *s; char_u *p; - int c; - int *inp; - - if (has_mbyte) { - // Use "sl_sal" as an array with 256 pointers to a list of wide - // characters. The index is the low byte of the character. - // The list contains from-to pairs with a terminating NUL. - // sl_sal_first[] is used for latin1 "from" characters. - gap = &lp->sl_sal; - ga_init(gap, sizeof(int *), 1); - ga_grow(gap, 256); - memset(gap->ga_data, 0, sizeof(int *) * 256); - gap->ga_len = 256; - - // First count the number of items for each list. Temporarily use - // sl_sal_first[] for this. - for (p = from, s = to; *p != NUL && *s != NUL; ) { - c = mb_cptr2char_adv((const char_u **)&p); - MB_CPTR_ADV(s); - if (c >= 256) { - lp->sl_sal_first[c & 0xff]++; - } - } - if (*p != NUL || *s != NUL) // lengths differ - return SP_FORMERROR; - // Allocate the lists. - for (i = 0; i < 256; ++i) - if (lp->sl_sal_first[i] > 0) { - p = xmalloc(sizeof(int) * (lp->sl_sal_first[i] * 2 + 1)); - ((int **)gap->ga_data)[i] = (int *)p; - *(int *)p = 0; - } + // Use "sl_sal" as an array with 256 pointers to a list of wide + // characters. The index is the low byte of the character. + // The list contains from-to pairs with a terminating NUL. + // sl_sal_first[] is used for latin1 "from" characters. + garray_T *gap = &lp->sl_sal; + ga_init(gap, sizeof(int *), 1); + ga_grow(gap, 256); + memset(gap->ga_data, 0, sizeof(int *) * 256); + gap->ga_len = 256; + + // First count the number of items for each list. Temporarily use + // sl_sal_first[] for this. + for (p = from, s = to; *p != NUL && *s != NUL; ) { + const int c = mb_cptr2char_adv((const char_u **)&p); + MB_CPTR_ADV(s); + if (c >= 256) { + lp->sl_sal_first[c & 0xff]++; + } + } + if (*p != NUL || *s != NUL) { // lengths differ + return SP_FORMERROR; + } - // Put the characters up to 255 in sl_sal_first[] the rest in a sl_sal - // list. - memset(lp->sl_sal_first, 0, sizeof(salfirst_T) * 256); - for (p = from, s = to; *p != NUL && *s != NUL; ) { - c = mb_cptr2char_adv((const char_u **)&p); - i = mb_cptr2char_adv((const char_u **)&s); - if (c >= 256) { - // Append the from-to chars at the end of the list with - // the low byte. - inp = ((int **)gap->ga_data)[c & 0xff]; - while (*inp != 0) - ++inp; - *inp++ = c; // from char - *inp++ = i; // to char - *inp++ = NUL; // NUL at the end - } else - // mapping byte to char is done in sl_sal_first[] - lp->sl_sal_first[c] = i; + // Allocate the lists. + for (int i = 0; i < 256; i++) { + if (lp->sl_sal_first[i] > 0) { + p = xmalloc(sizeof(int) * (lp->sl_sal_first[i] * 2 + 1)); + ((int **)gap->ga_data)[i] = (int *)p; + *(int *)p = 0; } - } else { - // mapping bytes to bytes is done in sl_sal_first[] - if (STRLEN(from) != STRLEN(to)) - return SP_FORMERROR; + } - for (i = 0; to[i] != NUL; ++i) - lp->sl_sal_first[from[i]] = to[i]; - lp->sl_sal.ga_len = 1; // indicates we have soundfolding + // Put the characters up to 255 in sl_sal_first[] the rest in a sl_sal + // list. + memset(lp->sl_sal_first, 0, sizeof(salfirst_T) * 256); + for (p = from, s = to; *p != NUL && *s != NUL; ) { + const int c = mb_cptr2char_adv((const char_u **)&p); + const int i = mb_cptr2char_adv((const char_u **)&s); + if (c >= 256) { + // Append the from-to chars at the end of the list with + // the low byte. + int *inp = ((int **)gap->ga_data)[c & 0xff]; + while (*inp != 0) { + inp++; + } + *inp++ = c; // from char + *inp++ = i; // to char + *inp++ = NUL; // NUL at the end + } else { + // mapping byte to char is done in sl_sal_first[] + lp->sl_sal_first[c] = i; + } } return 0; @@ -1572,40 +1561,35 @@ static void set_sal_first(slang_T *lp) sfirst[i] = -1; } smp = (salitem_T *)gap->ga_data; - for (int i = 0; i < gap->ga_len; ++i) { - if (has_mbyte) - // Use the lowest byte of the first character. For latin1 it's - // the character, for other encodings it should differ for most - // characters. - c = *smp[i].sm_lead_w & 0xff; - else - c = *smp[i].sm_lead; + for (int i = 0; i < gap->ga_len; i++) { + // Use the lowest byte of the first character. For latin1 it's + // the character, for other encodings it should differ for most + // characters. + c = *smp[i].sm_lead_w & 0xff; if (sfirst[c] == -1) { sfirst[c] = i; - if (has_mbyte) { - int n; - - // Make sure all entries with this byte are following each - // other. Move the ones that are in the wrong position. Do - // keep the same ordering! - while (i + 1 < gap->ga_len - && (*smp[i + 1].sm_lead_w & 0xff) == c) - // Skip over entry with same index byte. - ++i; - - for (n = 1; i + n < gap->ga_len; ++n) - if ((*smp[i + n].sm_lead_w & 0xff) == c) { - salitem_T tsal; - - // Move entry with same index byte after the entries - // we already found. - ++i; - --n; - tsal = smp[i + n]; - memmove(smp + i + 1, smp + i, - sizeof(salitem_T) * n); - smp[i] = tsal; - } + + // Make sure all entries with this byte are following each + // other. Move the ones that are in the wrong position. Do + // keep the same ordering! + while (i + 1 < gap->ga_len + && (*smp[i + 1].sm_lead_w & 0xff) == c) { + // Skip over entry with same index byte. + i++; + } + + for (int n = 1; i + n < gap->ga_len; n++) { + if ((*smp[i + n].sm_lead_w & 0xff) == c) { + salitem_T tsal; + + // Move entry with same index byte after the entries + // we already found. + i++; + n--; + tsal = smp[i + n]; + memmove(smp + i + 1, smp + i, sizeof(salitem_T) * n); + smp[i] = tsal; + } } } } @@ -2454,12 +2438,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // upper-case letter. if (aff_entry->ae_cond != NULL) { char_u buf[MAXLINELEN]; - if (has_mbyte) { - onecap_copy(items[4], buf, true); - aff_entry->ae_cond = getroom_save( - spin, buf); - } else - *aff_entry->ae_cond = c_up; + onecap_copy(items[4], buf, true); + aff_entry->ae_cond = getroom_save(spin, buf); if (aff_entry->ae_cond != NULL) { sprintf((char *)buf, "^%s", aff_entry->ae_cond); @@ -3373,13 +3353,9 @@ store_aff_word ( p = word; if (ae->ae_chop != NULL) { // Skip chop string. - if (has_mbyte) { - i = mb_charlen(ae->ae_chop); - for (; i > 0; i--) { - MB_PTR_ADV(p); - } - } else { - p += STRLEN(ae->ae_chop); + i = mb_charlen(ae->ae_chop); + for (; i > 0; i--) { + MB_PTR_ADV(p); } } STRCAT(newword, p); diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index ec6accd473..2f8b2989f5 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -2960,11 +2960,7 @@ static int check_keyword_id( char_u *const kwp = line + startcol; int kwlen = 0; do { - if (has_mbyte) { - kwlen += (*mb_ptr2len)(kwp + kwlen); - } else { - kwlen++; - } + kwlen += utfc_ptr2len(kwp + kwlen); } while (vim_iswordp_buf(kwp + kwlen, syn_buf)); if (kwlen > MAXKEYWLEN) { diff --git a/src/nvim/window.c b/src/nvim/window.c index 3429e3df70..4078cd31ac 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6151,11 +6151,7 @@ file_name_in_line ( // Skip over the "\" in "\ ". ++len; } - if (has_mbyte) { - len += (size_t)(*mb_ptr2len)(ptr + len); - } else { - ++len; - } + len += (size_t)(utfc_ptr2len(ptr + len)); } /* |