summaryrefslogtreecommitdiff
path: root/plugins/SpellChecker/src/hunspell/suggestmgr.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/SpellChecker/src/hunspell/suggestmgr.cxx')
-rw-r--r--plugins/SpellChecker/src/hunspell/suggestmgr.cxx60
1 files changed, 44 insertions, 16 deletions
diff --git a/plugins/SpellChecker/src/hunspell/suggestmgr.cxx b/plugins/SpellChecker/src/hunspell/suggestmgr.cxx
index 1fdf20c881..d89630849c 100644
--- a/plugins/SpellChecker/src/hunspell/suggestmgr.cxx
+++ b/plugins/SpellChecker/src/hunspell/suggestmgr.cxx
@@ -1,4 +1,4 @@
-#include "..\commons.h"
+#include "..\commons.h"
const w_char W_VLINE = { '\0', '|' };
@@ -97,7 +97,10 @@ int SuggestMgr::testsug(char** wlst, const char * candidate, int wl, int ns, int
int cwrd = 1;
if (ns == maxSug) return maxSug;
for (int k=0; k < ns; k++) {
- if (strcmp(candidate,wlst[k]) == 0) cwrd = 0;
+ if (strcmp(candidate,wlst[k]) == 0) {
+ cwrd = 0;
+ break;
+ }
}
if ((cwrd) && checkword(candidate, wl, cpdsuggest, timer, timelimit)) {
wlst[ns] = mystrdup(candidate);
@@ -354,8 +357,12 @@ int SuggestMgr::map_related(const char * word, char * candidate, int wn, int cn,
int cwrd = 1;
*(candidate + cn) = '\0';
int wl = strlen(candidate);
- for (int m=0; m < ns; m++)
- if (strcmp(candidate, wlst[m]) == 0) cwrd = 0;
+ for (int m=0; m < ns; m++) {
+ if (strcmp(candidate, wlst[m]) == 0) {
+ cwrd = 0;
+ break;
+ }
+ }
if ((cwrd) && checkword(candidate, wl, cpdsuggest, timer, timelimit)) {
if (ns < maxSug) {
wlst[ns] = mystrdup(candidate);
@@ -668,7 +675,7 @@ int SuggestMgr::extrachar(char** wlst, const char * word, int ns, int cpdsuggest
// error is missing a letter it needs
int SuggestMgr::forgotchar(char ** wlst, const char * word, int ns, int cpdsuggest)
{
- char candidate[MAXSWUTF8L];
+ char candidate[MAXSWUTF8L + 4];
char * p;
clock_t timelimit = clock();
int timer = MINTIMER;
@@ -690,8 +697,8 @@ int SuggestMgr::forgotchar(char ** wlst, const char * word, int ns, int cpdsugge
// error is missing a letter it needs
int SuggestMgr::forgotchar_utf(char ** wlst, const w_char * word, int wl, int ns, int cpdsuggest)
{
- w_char candidate_utf[MAXSWL];
- char candidate[MAXSWUTF8L];
+ w_char candidate_utf[MAXSWL + 1];
+ char candidate[MAXSWUTF8L + 4];
w_char * p;
clock_t timelimit = clock();
int timer = MINTIMER;
@@ -751,8 +758,12 @@ int SuggestMgr::twowords(char ** wlst, const char * word, int ns, int cpdsuggest
((c1 == 3) && (c2 >= 2)))) *p = '-';
cwrd = 1;
- for (int k=0; k < ns; k++)
- if (strcmp(candidate,wlst[k]) == 0) cwrd = 0;
+ for (int k=0; k < ns; k++) {
+ if (strcmp(candidate,wlst[k]) == 0) {
+ cwrd = 0;
+ break;
+ }
+ }
if (ns < maxSug) {
if (cwrd) {
wlst[ns] = mystrdup(candidate);
@@ -767,8 +778,12 @@ int SuggestMgr::twowords(char ** wlst, const char * word, int ns, int cpdsuggest
mystrlen(p + 1) > 1 &&
mystrlen(candidate) - mystrlen(p) > 1) {
*p = '-';
- for (int k=0; k < ns; k++)
- if (strcmp(candidate,wlst[k]) == 0) cwrd = 0;
+ for (int k=0; k < ns; k++) {
+ if (strcmp(candidate,wlst[k]) == 0) {
+ cwrd = 0;
+ break;
+ }
+ }
if (ns < maxSug) {
if (cwrd) {
wlst[ns] = mystrdup(candidate);
@@ -1250,6 +1265,10 @@ int SuggestMgr::ngsuggest(char** wlst, char * w, int ns, HashMgr** pHMgr, int md
break;
}
// using 2-gram instead of 3, and other weightening
+
+ re = ngram(2, word, gl, NGRAM_ANY_MISMATCH + low + NGRAM_WEIGHTED) +
+ ngram(2, gl, word, NGRAM_ANY_MISMATCH + low + NGRAM_WEIGHTED);
+
gscore[i] =
// length of longest common subsequent minus length difference
2 * _lcs - abs((int) (n - len)) +
@@ -1262,9 +1281,8 @@ int SuggestMgr::ngsuggest(char** wlst, char * w, int ns, HashMgr** pHMgr, int md
// ngram
ngram(4, word, gl, NGRAM_ANY_MISMATCH + low) +
// weighted ngrams
- (re = ngram(2, word, gl, NGRAM_ANY_MISMATCH + low + NGRAM_WEIGHTED)) +
- (re += ngram(2, gl, word, NGRAM_ANY_MISMATCH + low + NGRAM_WEIGHTED)) +
- // different limit for dictionaries with PHONE rules
+ re +
+ // different limit for dictionaries with PHONE rules
(ph ? (re < len * fact ? -1000 : 0) : (re < (n + len)*fact? -1000 : 0));
}
}
@@ -1320,7 +1338,10 @@ int SuggestMgr::ngsuggest(char** wlst, char * w, int ns, HashMgr** pHMgr, int md
if ((!guessorig[i] && strstr(guess[i], wlst[j])) ||
(guessorig[i] && strstr(guessorig[i], wlst[j])) ||
// check forbidden words
- !checkword(guess[i], strlen(guess[i]), 0, NULL, NULL)) unique = 0;
+ !checkword(guess[i], strlen(guess[i]), 0, NULL, NULL)) {
+ unique = 0;
+ break;
+ }
}
if (unique) {
wlst[ns++] = guess[i];
@@ -1348,7 +1369,10 @@ int SuggestMgr::ngsuggest(char** wlst, char * w, int ns, HashMgr** pHMgr, int md
// don't suggest previous suggestions or a previous suggestion with prefixes or affixes
if (strstr(rootsphon[i], wlst[j]) ||
// check forbidden words
- !checkword(rootsphon[i], strlen(rootsphon[i]), 0, NULL, NULL)) unique = 0;
+ !checkword(rootsphon[i], strlen(rootsphon[i]), 0, NULL, NULL)) {
+ unique = 0;
+ break;
+ }
}
if (unique) {
wlst[ns++] = mystrdup(rootsphon[i]);
@@ -1842,6 +1866,10 @@ int SuggestMgr::commoncharacterpositions(char * s1, const char * s2, int * is_sw
w_char su2[MAXSWL];
int l1 = u8_u16(su1, MAXSWL, s1);
int l2 = u8_u16(su2, MAXSWL, s2);
+
+ if (l1 <= 0 || l2 <= 0)
+ return 0;
+
// decapitalize dictionary word
if (complexprefixes) {
mkallsmall_utf(su2+l2-1, 1, langnum);