diff options
Diffstat (limited to 'src/nvim/spell.c')
-rw-r--r-- | src/nvim/spell.c | 97 |
1 files changed, 49 insertions, 48 deletions
diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 724a0332bc..5feb7efda9 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1910,11 +1910,11 @@ int init_syl_tab(slang_T *slang) // Count the number of syllables in "word". // When "word" contains spaces the syllables after the last space are counted. // Returns zero if syllables are not defines. -static int count_syllables(slang_T *slang, char_u *word) +static int count_syllables(slang_T *slang, const char_u *word) + FUNC_ATTR_NONNULL_ALL { int cnt = 0; bool skip = false; - char_u *p; int len; syl_item_T *syl; int c; @@ -1922,7 +1922,7 @@ static int count_syllables(slang_T *slang, char_u *word) if (slang->sl_syllable == NULL) return 0; - for (p = word; *p != NUL; p += len) { + for (const char_u *p = word; *p != NUL; p += len) { // When running into a space reset counter. if (*p == ' ') { len = 1; @@ -2031,7 +2031,8 @@ char_u *did_set_spelllang(win_T *wp) // Check if we loaded this language before. for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare(lang, slang->sl_fname, false) == kEqualFiles) { + if (path_full_compare(lang, slang->sl_fname, false, true) + == kEqualFiles) { break; } } @@ -2076,7 +2077,7 @@ char_u *did_set_spelllang(win_T *wp) // Loop over the languages, there can be several files for "lang". for (slang = first_lang; slang != NULL; slang = slang->sl_next) { if (filename - ? path_full_compare(lang, slang->sl_fname, false) == kEqualFiles + ? path_full_compare(lang, slang->sl_fname, false, true) == kEqualFiles : STRICMP(lang, slang->sl_name) == 0) { region_mask = REGION_ALL; if (!filename && region != NULL) { @@ -2129,7 +2130,7 @@ char_u *did_set_spelllang(win_T *wp) for (c = 0; c < ga.ga_len; ++c) { p = LANGP_ENTRY(ga, c)->lp_slang->sl_fname; if (p != NULL - && path_full_compare(spf_name, p, false) == kEqualFiles) { + && path_full_compare(spf_name, p, false, true) == kEqualFiles) { break; } } @@ -2139,7 +2140,8 @@ char_u *did_set_spelllang(win_T *wp) // Check if it was loaded already. for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare(spf_name, slang->sl_fname, false) == kEqualFiles) { + if (path_full_compare(spf_name, slang->sl_fname, false, true) + == kEqualFiles) { break; } } @@ -2568,36 +2570,33 @@ void init_spell_chartab(void) /// Thus this only works properly when past the first character of the word. /// /// @param wp Buffer used. -static bool spell_iswordp(char_u *p, win_T *wp) +static bool spell_iswordp(const char_u *p, const win_T *wp) + FUNC_ATTR_NONNULL_ALL { - char_u *s; - int l; int c; - if (has_mbyte) { - l = MB_PTR2LEN(p); - s = p; - if (l == 1) { - // be quick for ASCII - if (wp->w_s->b_spell_ismw[*p]) - s = p + 1; // skip a mid-word character - } else { - c = utf_ptr2char(p); - if (c < 256 ? wp->w_s->b_spell_ismw[c] - : (wp->w_s->b_spell_ismw_mb != NULL - && vim_strchr(wp->w_s->b_spell_ismw_mb, c) != NULL)) { - s = p + l; - } + const int l = utfc_ptr2len(p); + const char_u *s = p; + if (l == 1) { + // be quick for ASCII + if (wp->w_s->b_spell_ismw[*p]) { + s = p + 1; // skip a mid-word character } - - c = utf_ptr2char(s); - if (c > 255) { - return spell_mb_isword_class(mb_get_class(s), wp); + } else { + c = utf_ptr2char(p); + if (c < 256 + ? wp->w_s->b_spell_ismw[c] + : (wp->w_s->b_spell_ismw_mb != NULL + && vim_strchr(wp->w_s->b_spell_ismw_mb, c) != NULL)) { + s = p + l; } - return spelltab.st_isw[c]; } - return spelltab.st_isw[wp->w_s->b_spell_ismw[*p] ? p[1] : p[0]]; + c = utf_ptr2char(s); + if (c > 255) { + return spell_mb_isword_class(mb_get_class(s), wp); + } + return spelltab.st_isw[c]; } // Returns true if "p" points to a word character. @@ -2615,7 +2614,8 @@ bool spell_iswordp_nmw(const char_u *p, win_T *wp) // Only for characters above 255. // Unicode subscript and superscript are not considered word characters. // See also utf_class() in mbyte.c. -static bool spell_mb_isword_class(int cl, win_T *wp) +static bool spell_mb_isword_class(int cl, const win_T *wp) + FUNC_ATTR_PURE FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { if (wp->w_s->b_cjk) // East Asian characters are not considered word characters. @@ -2625,9 +2625,10 @@ static bool spell_mb_isword_class(int cl, win_T *wp) // Returns true if "p" points to a word character. // Wide version of spell_iswordp(). -static bool spell_iswordp_w(int *p, win_T *wp) +static bool spell_iswordp_w(const int *p, const win_T *wp) + FUNC_ATTR_NONNULL_ALL { - int *s; + const int *s; if (*p < 256 ? wp->w_s->b_spell_ismw[*p] : (wp->w_s->b_spell_ismw_mb != NULL @@ -3031,7 +3032,7 @@ void ex_spellrepall(exarg_T *eap) sub_nlines = 0; curwin->w_cursor.lnum = 0; while (!got_int) { - if (do_search(NULL, '/', frompat, 1L, SEARCH_KEEP, NULL, NULL) == 0 + if (do_search(NULL, '/', frompat, 1L, SEARCH_KEEP, NULL) == 0 || u_save_cursor() == FAIL) { break; } @@ -4116,7 +4117,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so && goodword_ends) { int l; - l = MB_PTR2LEN(fword + sp->ts_fidx); + l = utfc_ptr2len(fword + sp->ts_fidx); if (fword_ends) { // Copy the skipped character to preword. memmove(preword + sp->ts_prewordlen, @@ -4262,7 +4263,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Correct ts_fidx for the byte length of the // character (we didn't check that before). sp->ts_fidx = sp->ts_fcharstart - + MB_PTR2LEN(fword + sp->ts_fcharstart); + + utfc_ptr2len(fword + sp->ts_fcharstart); // For changing a composing character adjust // the score from SCORE_SUBST to @@ -4361,7 +4362,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // a bit illogical for soundfold tree but it does give better // results. c = utf_ptr2char(fword + sp->ts_fidx); - stack[depth].ts_fidx += MB_PTR2LEN(fword + sp->ts_fidx); + stack[depth].ts_fidx += utfc_ptr2len(fword + sp->ts_fidx); if (utf_iscomposing(c)) { stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; } else if (c == utf_ptr2char(fword + stack[depth].ts_fidx)) { @@ -4531,9 +4532,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNSWAP: // Undo the STATE_SWAP swap: "21" -> "12". p = fword + sp->ts_fidx; - n = MB_PTR2LEN(p); + n = utfc_ptr2len(p); c = utf_ptr2char(p + n); - memmove(p + MB_PTR2LEN(p + n), p, n); + memmove(p + utfc_ptr2len(p + n), p, n); utf_char2bytes(c, p); FALLTHROUGH; @@ -4587,11 +4588,11 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNSWAP3: // Undo STATE_SWAP3: "321" -> "123" p = fword + sp->ts_fidx; - n = MB_PTR2LEN(p); + n = utfc_ptr2len(p); c2 = utf_ptr2char(p + n); - fl = MB_PTR2LEN(p + n); + fl = utfc_ptr2len(p + n); c = utf_ptr2char(p + n + fl); - tl = MB_PTR2LEN(p + n + fl); + tl = utfc_ptr2len(p + n + fl); memmove(p + fl + tl, p, n); utf_char2bytes(c, p); utf_char2bytes(c2, p + tl); @@ -4635,10 +4636,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNROT3L: // Undo ROT3L: "231" -> "123" p = fword + sp->ts_fidx; - n = MB_PTR2LEN(p); - n += MB_PTR2LEN(p + n); + n = utfc_ptr2len(p); + n += utfc_ptr2len(p + n); c = utf_ptr2char(p + n); - tl = MB_PTR2LEN(p + n); + tl = utfc_ptr2len(p + n); memmove(p + tl, p, n); utf_char2bytes(c, p); @@ -4673,9 +4674,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Undo ROT3R: "312" -> "123" p = fword + sp->ts_fidx; c = utf_ptr2char(p); - tl = MB_PTR2LEN(p); - n = MB_PTR2LEN(p + tl); - n += MB_PTR2LEN(p + tl + n); + tl = utfc_ptr2len(p); + n = utfc_ptr2len(p + tl); + n += utfc_ptr2len(p + tl + n); memmove(p, p + tl, n); utf_char2bytes(c, p + n); |