Exemplo n.º 1
0
int spellcheck_suggest(void * chk, char ***sug, const char * word)
{
    struct linkgrammar_aspell *aspell = (struct linkgrammar_aspell *)chk;
    if (!sug) {
        prt_error("Error: Aspell. Corrupt pointer.\n");
        return 0;
    }
    if (aspell && aspell->speller) {
        const AspellWordList *list = NULL;
        AspellStringEnumeration *elem = NULL;
        const char *aword = NULL;
        unsigned int size, i;
        char **array = NULL;

        list = aspell_speller_suggest(aspell->speller, word, -1);
        elem = aspell_word_list_elements(list);
        size = aspell_word_list_size(list);
        /* allocate an array of char* for returning back to link-parser
         */
        array = (char **)malloc(sizeof(char *) * size);
        if (!array) {
            prt_error("Error: Aspell. Out of memory.\n");
            delete_aspell_string_enumeration(elem);
            return 0;
        }
        i = 0;
        while ((aword = aspell_string_enumeration_next(elem)) != NULL) {
            array[i++] = strdup(aword);
        }
        delete_aspell_string_enumeration(elem);
        *sug = array;
        return size;
    }
    return 0;
}
Exemplo n.º 2
0
/**
 * Utility function that wraps a list of words as ruby array of ruby strings.
 * @param list an aspell wordlist.
 * @return an ruby array, containing all words as ruby strings.
 */
static VALUE get_list(const AspellWordList *list) {
    VALUE result = rb_ary_new2(aspell_word_list_size(list));
    if (list != 0) {
        AspellStringEnumeration * els = aspell_word_list_elements(list);
        const char * word;
        while ( (word = aspell_string_enumeration_next(els)) != 0) {
            rb_ary_push(result, rb_str_new2(word));
        }
        delete_aspell_string_enumeration(els);
    }
    return result;
}
Exemplo n.º 3
0
QStringList SpellChecker::suggestions()
{
    QStringList sl;
    if ((spell_checker1 == 0) || (spell_checker2 == 0))
        return sl;
    QTextCursor cursor = m_textEdit->textCursor();
    cursor.select(QTextCursor::WordUnderCursor);
    QString word = cursor.selectedText();
    QByteArray ba = word.toUtf8();
    if ((aspell_speller_check(spell_checker2, ba.data(), ba.size()) != 0)||(aspell_speller_check(spell_checker1, ba.data(), ba.size()) != 0))
        return sl;
    const struct AspellWordList *awl = aspell_speller_suggest(spell_checker1, ba.data(), ba.size());
    if (aspell_word_list_size(awl) > 0) {
        struct AspellStringEnumeration *ase = aspell_word_list_elements(awl);
        int i  = 0;
        while ((!aspell_string_enumeration_at_end(ase))&&(i < 10)) {
            const char *text = aspell_string_enumeration_next(ase);
            sl << QString::fromUtf8(text);
            i++;
        }
        delete_aspell_string_enumeration(ase);
    }
    return sl;
}