Ejemplo n.º 1
0
void doChangeWord(GtkWidget* widget,gpointer data)
{
	pageStruct*	page=getPageStructPtr(-1);
	GtkTextIter	start;
	GtkTextIter	end;

	if((long)data==0)
		{
			if(gtk_text_buffer_get_selection_bounds((GtkTextBuffer*)page->buffer,&start,&end))
				{
					badWord=gtk_text_buffer_get_text((GtkTextBuffer*)page->buffer,&start,&end,false);
					if(badWord==NULL)
						return;
				}

			goodWord=gtk_combo_box_text_get_active_text((GtkComboBoxText*)wordListDropbox);
			gtk_text_buffer_delete((GtkTextBuffer*)page->buffer,&start,&end);
			gtk_text_buffer_insert((GtkTextBuffer*)page->buffer,&start,goodWord,-1);
			g_free(goodWord);
		}
	else
		goodWord=gtk_combo_box_text_get_active_text((GtkComboBoxText*)wordListDropbox);

	aspell_speller_store_replacement(spellChecker,badWord,-1,goodWord,-1);
	gtk_dialog_response((GtkDialog*)spellCheckWord,0);

	if(badWord!=NULL)
		g_free(badWord);
}
Ejemplo n.º 2
0
static void
replace_word(GtkWidget *menuitem, GtkSpell *spell) {
	char *oldword;
	const char *newword;
	GtkTextIter start, end;
	GtkTextBuffer *buffer;
	
	buffer = gtk_text_view_get_buffer(spell->view);

	get_cur_word_extents(buffer, &start, &end);
	oldword = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
	newword = gtk_label_get_text(GTK_LABEL(GTK_BIN(menuitem)->child));

	if (debug) {
		g_print("old word: '%s'\n", oldword);
		print_iter("s", &start); print_iter("e", &end);
		g_print("\nnew word: '%s'\n", newword);
	}

	gtk_text_buffer_delete(buffer, &start, &end);
	gtk_text_buffer_insert(buffer, &start, newword, -1);

	aspell_speller_store_replacement(spell->speller, 
			oldword, strlen(oldword),
			newword, strlen(newword));

	g_free(oldword);
}
Ejemplo n.º 3
0
/**
 * This method will check an array of strings for misspelled words.
 * This method needs a block to work proper. Each misspelled word is yielded,
 * a correct word as result from the block is assumed.
 * Common use:
 * 
 * a = Aspell.new(...)
 * text = ...
 * a.correct_lines(text) { |badword|
 *    puts "Error: #{badword}\n"
 *    puts a.suggest(badword).join(" | ")
 *    gets #the input is returned as right word
 * }
 * 
 * @param ary the array of strings to check.
 * @result an array holding all lines with corrected words.
 */
static VALUE aspell_correct_lines(VALUE self, VALUE ary) {
    VALUE result = ary;
    if (rb_block_given_p()) {
        //create checker
        AspellSpeller *speller = get_speller(self);
        AspellDocumentChecker * checker = get_checker(speller);
        AspellToken token;
        //some tmp values
        VALUE vline, sline;
        VALUE word, rword;
        char *line;
        int count=RARRAY_LEN(ary);
        int c=0;
        //create new result array
        result = rb_ary_new();
        //iterate over array
        while(c<count) {
            int offset=0;
            //fetch line
            vline = RARRAY_PTR(ary)[c];
            //save line
            sline = rb_funcall(vline, rb_intern("dup"), 0);
            //c representation
            line = STR2CSTR(vline);
            //process line
            aspell_document_checker_process(checker, line, -1);
            //iterate over all misspelled words
            while (token = aspell_document_checker_next_misspelling(checker), token.len != 0) {
                //extract word by start/length qualifier
                word = rb_funcall(vline, rb_intern("[]"), 2, INT2FIX(token.offset), INT2FIX(token.len));
                //get the right word from the block
                rword = rb_yield(word);
                //nil -> do nothing
                if(rword == Qnil) continue;
                //check for string
                if (TYPE(rword) != T_STRING) rb_raise(cAspellError, "%s", "Need a String to substitute");
                //chomp the string
                rb_funcall(rword, rb_intern("chomp!"), 0);
                //empty string -> do nothing
                if(strlen(STR2CSTR(rword)) == 0) continue;
                //remember word for later suggestion
                aspell_speller_store_replacement(speller, STR2CSTR(word), -1, STR2CSTR(rword), -1);
                //substitute the word by replacement
                rb_funcall(sline, rb_intern("[]="), 3, INT2FIX(token.offset+offset), INT2FIX(token.len), rword);
                //adjust offset
                offset += strlen(STR2CSTR(rword))-strlen(STR2CSTR(word));
                //printf("replace >%s< with >%s< (offset now %d)\n", STR2CSTR(word), STR2CSTR(rword), offset);
            }
            //push the substituted line to result
            rb_ary_push(result, sline);
            c++;
        }
        //free checker
        delete_aspell_document_checker(checker);
    } else {
        rb_raise(cAspellError, "%s", "No block given. How to correct?");
    }
    return result;
}
Ejemplo n.º 4
0
void CheckerString::replace(ParmString repl)
{
  assert(real_word_size_ > 0);
  int offset = real_word_begin_ - cur_line_->real.begin();
  aspell_speller_store_replacement(speller_, &*real_word_begin_, real_word_size_,
				   repl.str(), repl.size());
  cur_line_->real.replace(real_word_begin_, real_word_begin_ + real_word_size_,
                          repl.str(), repl.str() + repl.size());
  real_word_begin_ = cur_line_->real.begin() + offset;
  real_word_size_ = repl.size();
  fix_display_str();
  has_repl_ = true;
}
Ejemplo n.º 5
0
/* method:addReplacement ******************************************************/
static PyObject* m_addReplacement(PyObject* self, PyObject* args) {
	char *mis; int ml;
	char *cor; int cl;

	if (!PyArg_ParseTuple(args, "s#s#", &mis, &ml, &cor, &cl)) {
		PyErr_SetString(PyExc_TypeError, "two strings are required (misspelled, correct word)");
		return NULL;
	}
	aspell_speller_store_replacement(Speller(self), mis, ml, cor, cl);
	if (aspell_speller_error(Speller(self)) != 0) {
		PyErr_SetString(_AspellSpellerException, aspell_speller_error_message(Speller(self)));
		return NULL;
	}
	return_None;
}
Ejemplo n.º 6
0
/**
 * Remember a correction.
 * This affects the suggestion of other words to fit this correction.
 * @param badword the bad spelled word as string.
 * @param badword the correction of the bad spelled word as string.
 * @result self
 */
static VALUE aspell_store_replacement(VALUE self, VALUE badword, VALUE rightword) {
    AspellSpeller *speller = get_speller(self);
    aspell_speller_store_replacement(speller, STR2CSTR(badword), -1, STR2CSTR(rightword), -1);
    return self;
}