aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/spellsuggest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/spellsuggest.c')
-rw-r--r--src/nvim/spellsuggest.c87
1 files changed, 27 insertions, 60 deletions
diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c
index a7de20d14e..b37f01e769 100644
--- a/src/nvim/spellsuggest.c
+++ b/src/nvim/spellsuggest.c
@@ -14,6 +14,7 @@
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
+#include "nvim/errors.h"
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/typval_defs.h"
@@ -275,7 +276,6 @@ static bool can_be_compound(trystate_T *sp, slang_T *slang, uint8_t *compflags,
static int score_wordcount_adj(slang_T *slang, int score, char *word, bool split)
{
int bonus;
- int newscore;
hashitem_T *hi = hash_find(&slang->sl_wordcount, word);
if (HASHITEM_EMPTY(hi)) {
@@ -290,11 +290,8 @@ static int score_wordcount_adj(slang_T *slang, int score, char *word, bool split
} else {
bonus = SCORE_COMMON3;
}
- if (split) {
- newscore = score - bonus / 2;
- } else {
- newscore = score - bonus;
- }
+ int newscore = split ? score - bonus / 2
+ : score - bonus;
if (newscore < 0) {
return 0;
}
@@ -448,7 +445,6 @@ void spell_suggest(int count)
suginfo_T sug;
suggest_T *stp;
bool mouse_used;
- int limit;
int selected = count;
int badlen = 0;
int msg_scroll_save = msg_scroll;
@@ -480,9 +476,7 @@ void spell_suggest(int count)
badlen++;
end_visual_mode();
// make sure we don't include the NUL at the end of the line
- if (badlen > get_cursor_line_len() - curwin->w_cursor.col) {
- badlen = get_cursor_line_len() - curwin->w_cursor.col;
- }
+ badlen = MIN(badlen, get_cursor_line_len() - curwin->w_cursor.col);
// Find the start of the badly spelled word.
} else if (spell_move_to(curwin, FORWARD, SMT_ALL, true, NULL) == 0
|| curwin->w_cursor.col > prev_cursor.col) {
@@ -518,11 +512,7 @@ void spell_suggest(int count)
// Get the list of suggestions. Limit to 'lines' - 2 or the number in
// 'spellsuggest', whatever is smaller.
- if (sps_limit > Rows - 2) {
- limit = Rows - 2;
- } else {
- limit = sps_limit;
- }
+ int limit = MIN(sps_limit, Rows - 2);
spell_find_suggest(line + curwin->w_cursor.col, badlen, &sug, limit,
true, need_cap, true);
@@ -642,7 +632,7 @@ void spell_suggest(int count)
int c = (int)(sug.su_badptr - line);
memmove(p, line, (size_t)c);
STRCPY(p + c, stp->st_word);
- STRCAT(p, sug.su_badptr + stp->st_orglen);
+ strcat(p, sug.su_badptr + stp->st_orglen);
// For redo we use a change-word command.
ResetRedobuff();
@@ -730,10 +720,7 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc
}
su->su_maxcount = maxcount;
su->su_maxscore = SCORE_MAXINIT;
-
- if (su->su_badlen >= MAXWLEN) {
- su->su_badlen = MAXWLEN - 1; // just in case
- }
+ su->su_badlen = MIN(su->su_badlen, MAXWLEN - 1); // just in case
xmemcpyz(su->su_badword, su->su_badptr, (size_t)su->su_badlen);
spell_casefold(curwin, su->su_badptr, su->su_badlen, su->su_fbadword,
MAXWLEN);
@@ -1144,7 +1131,6 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
idx_T *idxs, *fidxs, *pidxs;
int c, c2, c3;
int n = 0;
- garray_T *gap;
idx_T arridx;
int fl = 0;
int tl;
@@ -1637,7 +1623,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
// Append a space to preword when splitting.
if (!try_compound && !fword_ends) {
- STRCAT(preword, " ");
+ strcat(preword, " ");
}
sp->ts_prewordlen = (uint8_t)strlen(preword);
sp->ts_splitoff = sp->ts_twordlen;
@@ -1735,11 +1721,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
// Done all bytes at this node, do next state. When still at
// already changed bytes skip the other tricks.
PROF_STORE(sp->ts_state)
- if (sp->ts_fidx >= sp->ts_fidxtry) {
- sp->ts_state = STATE_DEL;
- } else {
- sp->ts_state = STATE_FINAL;
- }
+ sp->ts_state = sp->ts_fidx >= sp->ts_fidxtry ? STATE_DEL
+ : STATE_FINAL;
} else {
arridx += sp->ts_curi++;
c = byts[arridx];
@@ -1809,10 +1792,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
// 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))) {
+ if (utf_iscomposing_legacy(utf_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen))
+ && utf_iscomposing_legacy(utf_ptr2char(fword + sp->ts_fcharstart))) {
sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP;
} else if (!soundfold
&& slang->sl_has_map
@@ -1828,7 +1809,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
&& sp->ts_twordlen > sp->ts_tcharlen) {
p = tword + sp->ts_twordlen - sp->ts_tcharlen;
c = utf_ptr2char(p);
- if (utf_iscomposing(c)) {
+ if (utf_iscomposing_legacy(c)) {
// Inserting a composing char doesn't
// count that much.
sp->ts_score -= SCORE_INS - SCORE_INSCOMP;
@@ -1893,7 +1874,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
c = utf_ptr2char(fword + sp->ts_fidx);
stack[depth].ts_fidx =
(uint8_t)(stack[depth].ts_fidx + utfc_ptr2len(fword + sp->ts_fidx));
- if (utf_iscomposing(c)) {
+ if (utf_iscomposing_legacy(c)) {
stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP;
} else if (c == utf_ptr2char(fword + stack[depth].ts_fidx)) {
stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP;
@@ -2253,11 +2234,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
// valid.
p = fword + sp->ts_fidx;
- if (soundfold) {
- gap = &slang->sl_repsal;
- } else {
- gap = &lp->lp_replang->sl_rep;
- }
+ garray_T *gap = soundfold ? &slang->sl_repsal
+ : &lp->lp_replang->sl_rep;
while (sp->ts_curi < gap->ga_len) {
fromto_T *ftp = (fromto_T *)gap->ga_data + sp->ts_curi++;
if (*ftp->ft_from != *p) {
@@ -3125,11 +3103,9 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i
// the best suggestions.
if (gap->ga_len > SUG_MAX_COUNT(su)) {
if (maxsf) {
- su->su_sfmaxscore = cleanup_suggestions(gap,
- su->su_sfmaxscore, SUG_CLEAN_COUNT(su));
+ su->su_sfmaxscore = cleanup_suggestions(gap, su->su_sfmaxscore, SUG_CLEAN_COUNT(su));
} else {
- su->su_maxscore = cleanup_suggestions(gap,
- su->su_maxscore, SUG_CLEAN_COUNT(su));
+ su->su_maxscore = cleanup_suggestions(gap, su->su_maxscore, SUG_CLEAN_COUNT(su));
}
}
}
@@ -3275,8 +3251,6 @@ static int soundalike_score(char *goodstart, char *badstart)
{
char *goodsound = goodstart;
char *badsound = badstart;
- char *pl, *ps;
- char *pl2, *ps2;
int score = 0;
// Adding/inserting "*" at the start (word starts with vowel) shouldn't be
@@ -3317,13 +3291,10 @@ static int soundalike_score(char *goodstart, char *badstart)
return SCORE_MAXMAX;
}
- if (n > 0) {
- pl = goodsound; // goodsound is longest
- ps = badsound;
- } else {
- pl = badsound; // badsound is longest
- ps = goodsound;
- }
+ // n > 0 : goodsound is longest
+ // n <= 0 : badsound is longest
+ char *pl = n > 0 ? goodsound : badsound;
+ char *ps = n > 0 ? badsound : goodsound;
// Skip over the identical part.
while (*pl == *ps && *pl != NUL) {
@@ -3331,6 +3302,8 @@ static int soundalike_score(char *goodstart, char *badstart)
ps++;
}
+ char *pl2, *ps2;
+
switch (n) {
case -2:
case 2:
@@ -3551,19 +3524,13 @@ static int spell_edit_score(slang_T *slang, const char *badword, const char *goo
int pgc = wgoodword[j - 2];
if (bc == pgc && pbc == gc) {
int t = SCORE_SWAP + CNT(i - 2, j - 2);
- if (t < CNT(i, j)) {
- CNT(i, j) = t;
- }
+ CNT(i, j) = MIN(CNT(i, j), t);
}
}
int t = SCORE_DEL + CNT(i - 1, j);
- if (t < CNT(i, j)) {
- CNT(i, j) = t;
- }
+ CNT(i, j) = MIN(CNT(i, j), t);
t = SCORE_INS + CNT(i, j - 1);
- if (t < CNT(i, j)) {
- CNT(i, j) = t;
- }
+ CNT(i, j) = MIN(CNT(i, j), t);
}
}
}