static gchar* lw_morphologyengine_hunspell_spellcheck (LwMorphologyEngine *engine, const gchar *WORD) { //Sanity checks if (engine == NULL) return NULL; if (engine->hunspell == NULL) return NULL; if (WORD == NULL) return NULL; if (Hunspell_spell (engine->hunspell, WORD) != 0) return NULL; //Delarations gchar **suggestions = NULL; GString *output = NULL; gint i = 0; gint total = 0; //Initializations total = Hunspell_suggest (engine->hunspell, &suggestions, WORD); output = g_string_new (""); if (suggestions != NULL) { for (i = 0; i < total; i++) { if (*output->str == '\0') g_string_assign (output, suggestions[i]); else g_string_append_printf (output, LW_MORPHOLOGY_SPELLCHECK_DELIMITOR "%s", suggestions[i]); } Hunspell_free_list (engine->hunspell, &suggestions, total); suggestions = NULL; } return g_string_free (output, total < 1); }
static gchar* lw_morphologyengine_hunspell_stem (LwMorphologyEngine *engine, const gchar *WORD) { //Sanity checks if (engine == NULL) return NULL; if (engine->hunspell == NULL) return NULL; if (WORD == NULL) return NULL; gchar **suggestions; gint total; gchar *output; gint i; total = Hunspell_stem (engine->hunspell, &suggestions, WORD); output = NULL; if (suggestions != NULL) { for (i = total - 1; i >= 0 && output == NULL; i--) //The results at the end tend to be the most core form { if (g_ascii_strcasecmp (WORD, suggestions[i]) != 0) //Make sure we aren't just getting the lower case form of the word output = g_strdup (suggestions[i]); } Hunspell_free_list (engine->hunspell, &suggestions, total); suggestions = NULL; } return output; }
void TCommandLine::slot_popupMenu() { auto* pA = qobject_cast<QAction*>(sender()); if (!pA) { return; } QString t = pA->text(); QTextCursor c = cursorForPosition(mPopupPosition); c.select(QTextCursor::WordUnderCursor); c.removeSelectedText(); c.insertText(t); c.clearSelection(); Hunspell_free_list(mpHunspell, &mpHunspellSuggestionList, mHunspellSuggestionNumber); }
static PyObject * HunSpell_analyze(HunSpell * self, PyObject *args) { char *word, **slist; int i, num_slist; PyObject *slist_list; if (!PyArg_ParseTuple(args, "s", &word)) return NULL; slist_list = PyList_New(0); num_slist = Hunspell_analyze(self->handle, &slist, word); for (i = 0; i < num_slist; i++) { PyList_Append(slist_list, Py_BuildValue("s", slist[i])); } Hunspell_free_list(self->handle, &slist, num_slist); return slist_list; }
static PyObject * HunSpell_generate(HunSpell * self, PyObject *args) { char *word1, *word2, **slist; int i, num_slist; PyObject *slist_list; if (!PyArg_ParseTuple(args, "etet", self->encoding, &word1, self->encoding, &word2)) return NULL; slist_list = PyList_New(0); num_slist = Hunspell_generate(self->handle, &slist, word1, word2); PyMem_Free(word1); PyMem_Free(word2); for (i = 0; i < num_slist; i++) { PyList_Append(slist_list, Py_BuildValue("s", slist[i])); } Hunspell_free_list(self->handle, &slist, num_slist); return slist_list; }
void spellcheck_free_suggest(void *chk, char **sug, int size) { Hunspell_free_list((Hunhandle *)chk, &sug, size); }
void CheckRESpelling(HWND hEdit){ TEXTRANGEW trg = {0}; wchar_t *wpText = NULL, *wpt, *pw, *ptrW, *wpos; GETTEXTLENGTHEX gtx; long charCount; char *pText = NULL, *p, *w, **arr; int result, countSuggs = 0, len, findRes = 0; SUGGARRAY suggs = {0}; FINDTEXTEXW ft = {0}; __try{ SetCursor(LoadCursor(NULL, IDC_WAIT)); suggs.hEdit = hEdit; gtx.flags = GTL_NUMCHARS | GTL_PRECISE; gtx.codepage = 1200; charCount = SendMessageW(hEdit, EM_GETTEXTLENGTHEX, (WPARAM)>x, 0); wpText = calloc(charCount + 1, sizeof(wchar_t)); trg.chrg.cpMin = 0; trg.chrg.cpMax = charCount + 1; trg.lpstrText = wpText; SendMessageW(hEdit, EM_GETTEXTRANGE, 0, (LPARAM)&trg); ft.chrg = trg.chrg; pText = calloc(charCount + 1, sizeof(char)); WideCharToMultiByte(m_CodePage, 0, wpText, -1, pText, charCount, NULL, NULL); p = pText; pw = wpText; w = strtok(p, DELIMETERS); wpos = wcstok(pw, DELIMITERSW, &ptrW); while(w){ result = Hunspell_spell(m_hh, w); if(result == 0){ len = strlen(w) + 1; wpt = calloc(len, sizeof(wchar_t)); MultiByteToWideChar(m_CodePage, 0, w, -1, wpt, len - 1); if(suggs.count == 0){ suggs.pSuggs = calloc(1, sizeof(PSUGGESTION)); } else{ suggs.pSuggs = realloc(suggs.pSuggs, sizeof(PSUGGESTION) * (suggs.count + 1)); suggs.pSuggs[suggs.count] = NULL; } ft.lpstrText = wpos; findRes = SendMessageW(hEdit, EM_FINDTEXTEXW, FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD, (LPARAM)&ft); _addSuggestion(&suggs.pSuggs[suggs.count], wpt, findRes); ft.chrg.cpMin = findRes + wcslen(wpos); free(wpt); countSuggs = Hunspell_suggest(m_hh, &arr, w); if(countSuggs > 0){ for(int i = 0; i < countSuggs; i++){ len = strlen(arr[i]) + 1; wpt = calloc(len, sizeof(wchar_t)); MultiByteToWideChar(m_CodePage, 0, arr[i], -1, wpt, len - 1); _addSuggestion(&suggs.pSuggs[suggs.count], wpt, len); free(wpt); } Hunspell_free_list(m_hh, &arr, countSuggs); } suggs.count++; } w = strtok(NULL, DELIMETERS); wpos = wcstok(NULL, DELIMITERSW, &ptrW); } } __finally{ if(pText) free(pText); if(wpText) free(wpText); SetCursor(LoadCursor(NULL, IDC_ARROW)); } if(suggs.count > 0){ DialogBoxParamW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(DLG_SPELLING), GetParent(hEdit), Spelling_DlgProc, (LPARAM)&suggs); free(suggs.pSuggs); } else{ wchar_t szBuffer[512]; GetPrivateProfileStringW(L"options", L"1052", L"Spell checking", szBuffer, 256, g_NotePaths.CurrLanguagePath); MessageBoxW(GetParent(hEdit), g_Strings.SpellCheckComplete, szBuffer, MB_OK); } }
PSUGGESTION SuggestionsForRightClick(HWND hEdit, POINT pt){ TEXTRANGEW trg = {0}, trWord = {0}; wchar_t *wpText = NULL, *wpt = NULL, *pStr; GETTEXTLENGTHEX gtx; long i1, i2; char *w = NULL, **arr; int result, countSuggs = 0, len; LRESULT selChar, charCount; PSUGGESTION ps = NULL; __try{ gtx.flags = GTL_NUMCHARS | GTL_PRECISE; gtx.codepage = 1200; charCount = SendMessageW(hEdit, EM_GETTEXTLENGTHEX, (WPARAM)>x, 0); if(charCount == 0) return NULL; wpText = calloc(charCount + 1, sizeof(wchar_t)); trg.chrg.cpMin = 0; trg.chrg.cpMax = charCount + 1; trg.lpstrText = wpText; SendMessageW(hEdit, EM_GETTEXTRANGE, 0, (LPARAM)&trg); selChar = SendMessageW(hEdit, EM_CHARFROMPOS, 0, (LPARAM)&pt); if(wcschr(DELIMITERSW, wpText[selChar])) return NULL; i1 = i2 = selChar; while(TRUE){ if((i1 == 0 && wcschr(DELIMITERSW, wpText[i2])) || (i1 == 0 && i2 == charCount - 1) || (wcschr(DELIMITERSW, wpText[i1]) && wcschr(DELIMITERSW, wpText[i2])) || (wcschr(DELIMITERSW, wpText[i1]) && i2 == charCount - 1)){ break; } if(i1 > 0 && !wcschr(DELIMITERSW, wpText[i1])) i1--; if(i2 < charCount - 1 && !wcschr(DELIMITERSW, wpText[i2])) i2++; } if(i2 == charCount - 1 && !wcschr(DELIMITERSW, wpText[i2])){ i2++; } wpt = calloc(i2 - i1 + 1, sizeof(wchar_t)); trWord.chrg.cpMin = (i1 > 0) ? (i1 + 1) : (wcschr(DELIMITERSW, wpText[i1]) ? 1 : 0); trWord.chrg.cpMax = (i2 == charCount) ? ((wcschr(DELIMITERSW, wpText[i2]) && wpText[i2] != '\0') ? i2 - 1 : i2) : i2;// < charCount - 1 ? i2 - 1 : i2; trWord.lpstrText = wpt; SendMessageW(hEdit, EM_GETTEXTRANGE, 0, (LPARAM)&trWord); len = i2 - i1 + 1; w = calloc(len, sizeof(char)); WideCharToMultiByte(m_CodePage, 0, wpt, -1, w, len - 1, NULL, NULL); result = Hunspell_spell(m_hh, w); if(result == 0){ _addSuggestion(&ps, wpt, trWord.chrg.cpMin); countSuggs = Hunspell_suggest(m_hh, &arr, w); if(countSuggs > 0){ for(int i = 0; i < countSuggs; i++){ len = strlen(arr[i]) + 1; pStr = calloc(len, sizeof(wchar_t)); MultiByteToWideChar(m_CodePage, 0, arr[i], -1, pStr, len); _addSuggestion(&ps, pStr, len); free(pStr); } Hunspell_free_list(m_hh, &arr, countSuggs); } } return ps; } __finally{ if(wpText) free(wpText); if(wpt) free(wpt); if(w) free(w); } return NULL; }