aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/spell.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/spell.c')
-rw-r--r--src/nvim/spell.c80
1 files changed, 39 insertions, 41 deletions
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 9ed421c8a0..20081bce4f 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -397,7 +397,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou
bool this_upper = false; // init for gcc
if (use_camel_case) {
- c = PTR2CHAR(mi.mi_fend);
+ c = utf_ptr2char(mi.mi_fend);
this_upper = SPELL_ISUPPER(c);
}
@@ -405,7 +405,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou
MB_PTR_ADV(mi.mi_fend);
if (use_camel_case) {
const bool prev_upper = this_upper;
- c = PTR2CHAR(mi.mi_fend);
+ c = utf_ptr2char(mi.mi_fend);
this_upper = SPELL_ISUPPER(c);
camel_case = !prev_upper && this_upper;
}
@@ -414,7 +414,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou
if (capcol != NULL && *capcol == 0 && wp->w_s->b_cap_prog != NULL) {
// Check word starting with capital letter.
- c = PTR2CHAR(ptr);
+ c = utf_ptr2char(ptr);
if (!SPELL_ISUPPER(c)) {
wrongcaplen = (size_t)(mi.mi_fend - ptr);
}
@@ -634,7 +634,7 @@ static void find_word(matchinf_T *mip, int mode)
if (byts[arridx] == 0) {
if (endidxcnt == MAXWLEN) {
// Must be a corrupted spell file.
- EMSG(_(e_format));
+ emsg(_(e_format));
return;
}
endlen[endidxcnt] = wlen;
@@ -1386,7 +1386,7 @@ static bool no_spell_checking(win_T *wp)
{
if (!wp->w_p_spell || *wp->w_s->b_p_spl == NUL
|| GA_EMPTY(&wp->w_s->b_langp)) {
- EMSG(_(e_no_spell));
+ emsg(_(e_no_spell));
return true;
}
return false;
@@ -1758,7 +1758,8 @@ void slang_free(slang_T *lp)
}
/// Frees a salitem_T
-static void free_salitem(salitem_T *smp) {
+static void free_salitem(salitem_T *smp)
+{
xfree(smp->sm_lead);
// Don't free sm_oneof and sm_rules, they point into sm_lead.
xfree(smp->sm_to);
@@ -1768,7 +1769,8 @@ static void free_salitem(salitem_T *smp) {
}
/// Frees a fromto_T
-static void free_fromto(fromto_T *ftp) {
+static void free_fromto(fromto_T *ftp)
+{
xfree(ftp->ft_from);
xfree(ftp->ft_to);
}
@@ -2022,7 +2024,7 @@ static int count_syllables(slang_T *slang, const char_u *word)
} else {
// No recognized syllable item, at least a syllable char then?
c = utf_ptr2char(p);
- len = (*mb_ptr2len)(p);
+ len = utfc_ptr2len(p);
if (vim_strchr(slang->sl_syllable, c) == NULL) {
skip = false; // No, search for next syllable
} else if (!skip) {
@@ -2036,7 +2038,7 @@ static int count_syllables(slang_T *slang, const char_u *word)
// Parse 'spelllang' and set w_s->b_langp accordingly.
// Returns NULL if it's OK, an error message otherwise.
-char_u *did_set_spelllang(win_T *wp)
+char *did_set_spelllang(win_T *wp)
{
garray_T ga;
char_u *splp;
@@ -2057,7 +2059,7 @@ char_u *did_set_spelllang(win_T *wp)
bool nobreak = false;
langp_T *lp, *lp2;
static bool recursive = false;
- char_u *ret_msg = NULL;
+ char *ret_msg = NULL;
char_u *spl_copy;
bufref_T bufref;
@@ -2155,8 +2157,7 @@ char_u *did_set_spelllang(win_T *wp)
// SpellFileMissing autocommands may do anything, including
// destroying the buffer we are using...
if (!bufref_valid(&bufref)) {
- ret_msg =
- (char_u *)N_("E797: SpellFileMissing autocommand deleted buffer");
+ ret_msg = N_("E797: SpellFileMissing autocommand deleted buffer");
goto theend;
}
}
@@ -2422,7 +2423,7 @@ int captype(char_u *word, char_u *end)
// But a word with an upper char only at start is a ONECAP.
for (; end == NULL ? *p != NUL : p < end; MB_PTR_ADV(p)) {
if (spell_iswordp_nmw(p, curwin)) {
- c = PTR2CHAR(p);
+ c = utf_ptr2char(p);
if (!SPELL_ISUPPER(c)) {
// UUl -> KEEPCAP
if (past_second && allcap) {
@@ -2463,7 +2464,7 @@ static int badword_captype(char_u *word, char_u *end)
l = u = 0;
first = false;
for (p = word; p < end; MB_PTR_ADV(p)) {
- c = PTR2CHAR(p);
+ c = utf_ptr2char(p);
if (SPELL_ISUPPER(c)) {
++u;
if (p == word) {
@@ -2870,7 +2871,7 @@ void spell_suggest(int count)
}
if (*curwin->w_s->b_p_spl == NUL) {
- EMSG(_(e_no_spell));
+ emsg(_(e_no_spell));
return;
}
@@ -2933,7 +2934,7 @@ void spell_suggest(int count)
true, need_cap, true);
if (GA_EMPTY(&sug.su_ga)) {
- MSG(_("Sorry, no suggestions"));
+ msg(_("Sorry, no suggestions"));
} else if (count > 0) {
if (count > sug.su_ga.ga_len) {
smsg(_("Sorry, only %" PRId64 " suggestions"),
@@ -3149,7 +3150,7 @@ void ex_spellrepall(exarg_T *eap)
linenr_T prev_lnum = 0;
if (repl_from == NULL || repl_to == NULL) {
- EMSG(_("E752: No previous spell replacement"));
+ emsg(_("E752: No previous spell replacement"));
return;
}
addlen = (int)(STRLEN(repl_to) - STRLEN(repl_from));
@@ -3193,7 +3194,7 @@ void ex_spellrepall(exarg_T *eap)
xfree(frompat);
if (sub_nsubs == 0) {
- EMSG2(_("E753: Not found: %s"), repl_from);
+ semsg(_("E753: Not found: %s"), repl_from);
} else {
do_sub_msg(false);
}
@@ -3313,7 +3314,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma
// If the word is not capitalised and spell_check() doesn't consider the
// word to be bad then it might need to be capitalised. Add a suggestion
// for that.
- c = PTR2CHAR(su->su_badptr);
+ c = utf_ptr2char(su->su_badptr);
if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) {
make_case_word(su->su_badword, buf, WF_ONECAP);
add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE,
@@ -3404,7 +3405,7 @@ static void spell_suggest_file(suginfo_T *su, char_u *fname)
// Open the file.
fd = os_fopen((char *)fname, "r");
if (fd == NULL) {
- EMSG2(_(e_notopen), fname);
+ semsg(_(e_notopen), fname);
return;
}
@@ -3420,7 +3421,6 @@ static void spell_suggest_file(suginfo_T *su, char_u *fname)
if (STRICMP(su->su_badword, line) == 0) {
// Match! Isolate the good word, until CR or NL.
for (len = 0; p[len] >= ' '; ++len) {
- ;
}
p[len] = NUL;
@@ -3813,7 +3813,6 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
if (sp->ts_prefixdepth == PFD_PREFIXTREE) {
// Skip over the NUL bytes, we use them later.
for (n = 0; n < len && byts[arridx + n] == 0; ++n) {
- ;
}
sp->ts_curi += n;
@@ -3888,7 +3887,6 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
n = stack[sp->ts_prefixdepth].ts_arridx;
len = pbyts[n++];
for (c = 0; c < len && pbyts[n + c] == 0; ++c) {
- ;
}
if (c > 0) {
c = valid_word_prefix(c, n, flags,
@@ -4010,7 +4008,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
c = su->su_badflags;
if ((c & WF_ALLCAP)
&& su->su_badlen ==
- (*mb_ptr2len)(su->su_badptr)) {
+ utfc_ptr2len(su->su_badptr)) {
c = WF_ONECAP;
}
c |= flags;
@@ -4611,7 +4609,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
break;
}
- n = MB_CPTR2LEN(p);
+ n = utf_ptr2len(p);
c = utf_ptr2char(p);
if (p[n] == NUL) {
c2 = NUL;
@@ -4646,7 +4644,7 @@ 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++;
- fl = mb_char2len(c2);
+ fl = utf_char2len(c2);
memmove(p, p + n, fl);
utf_char2bytes(c, p + fl);
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
@@ -4671,9 +4669,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// Swap two bytes, skipping one: "123" -> "321". We change
// "fword" here, it's changed back afterwards at STATE_UNSWAP3.
p = fword + sp->ts_fidx;
- n = MB_CPTR2LEN(p);
+ n = utf_ptr2len(p);
c = utf_ptr2char(p);
- fl = MB_CPTR2LEN(p + n);
+ fl = utf_ptr2len(p + n);
c2 = utf_ptr2char(p + n);
if (!soundfold && !spell_iswordp(p + n + fl, curwin)) {
c3 = c; // don't swap non-word char
@@ -4702,7 +4700,7 @@ 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++;
- tl = mb_char2len(c3);
+ tl = utf_char2len(c3);
memmove(p, p + n + fl, tl);
utf_char2bytes(c2, p + tl);
utf_char2bytes(c, p + fl + tl);
@@ -4748,10 +4746,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
sp->ts_state = STATE_UNROT3L;
++depth;
p = fword + sp->ts_fidx;
- n = MB_CPTR2LEN(p);
+ n = utf_ptr2len(p);
c = utf_ptr2char(p);
- fl = MB_CPTR2LEN(p + n);
- fl += MB_CPTR2LEN(p + n + fl);
+ fl = utf_ptr2len(p + n);
+ fl += utf_ptr2len(p + n + fl);
memmove(p, p + n, fl);
utf_char2bytes(c, p + fl);
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
@@ -4785,10 +4783,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
sp->ts_state = STATE_UNROT3R;
++depth;
p = fword + sp->ts_fidx;
- n = MB_CPTR2LEN(p);
- n += MB_CPTR2LEN(p + n);
+ n = utf_ptr2len(p);
+ n += utf_ptr2len(p + n);
c = utf_ptr2char(p + n);
- tl = MB_CPTR2LEN(p + n);
+ tl = utf_ptr2len(p + n);
memmove(p + tl, p, n);
utf_char2bytes(c, p);
stack[depth].ts_fidxtry = sp->ts_fidx + n + tl;
@@ -5023,8 +5021,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.
- flen = MB_CPTR2LEN(fword + fwordidx[depth]);
- ulen = MB_CPTR2LEN(uword + uwordidx[depth]);
+ flen = utf_ptr2len(fword + fwordidx[depth]);
+ ulen = utf_ptr2len(uword + uwordidx[depth]);
if (round[depth] == 1) {
p = fword + fwordidx[depth];
l = flen;
@@ -5514,9 +5512,9 @@ badword:
// lower to upper case. Helps for "tath" -> "Kath", which is
// less common than "tath" -> "path". Don't do it when the
// letter is the same, that has already been counted.
- gc = PTR2CHAR(p);
+ gc = utf_ptr2char(p);
if (SPELL_ISUPPER(gc)) {
- bc = PTR2CHAR(su->su_badword);
+ bc = utf_ptr2char(su->su_badword);
if (!SPELL_ISUPPER(bc)
&& SPELL_TOFOLD(bc) != SPELL_TOFOLD(gc)) {
goodscore += SCORE_ICASE / 2;
@@ -6938,7 +6936,7 @@ void spell_dump_compl(char_u *pat, int ic, Direction *dir, int dumpflags_arg)
if (n == WF_ONECAP) {
dumpflags |= DUMPFLAG_ONECAP;
} else if (n == WF_ALLCAP
- && (int)STRLEN(pat) > mb_ptr2len(pat)) {
+ && (int)STRLEN(pat) > utfc_ptr2len(pat)) {
dumpflags |= DUMPFLAG_ALLCAP;
}
}
@@ -7187,7 +7185,7 @@ static linenr_T dump_prefixes(slang_T *slang, char_u *word, char_u *pat, Directi
// If the word starts with a lower-case letter make the word with an
// upper-case letter in word_up[].
- c = PTR2CHAR(word);
+ c = utf_ptr2char(word);
if (SPELL_TOUPPER(c) != c) {
onecap_copy(word, word_up, true);
has_word_up = true;