PosibErr<void> Dictionary::add_repl(ParmString mis, ParmString cor) { if (!invisible_soundslike) { VARARRAY(char, sl, mis.size() + 1); lang()->LangImpl::to_soundslike(sl, mis.str(), mis.size()); return add_repl(mis, cor, sl); } else {
short edit_distance(ParmString a0, ParmString b0, const EditDistanceWeights & w) { int a_size = a0.size() + 1; int b_size = b0.size() + 1; VARARRAY(short, e_d, a_size * b_size); ShortMatrix e(a_size,b_size,e_d); e(0, 0) = 0; for (int j = 1; j != b_size; ++j) e(0, j) = e(0, j-1) + w.del1; const char * a = a0.str() - 1; const char * b = b0.str() - 1; short te; for (int i = 1; i != a_size; ++i) { e(i, 0) = e(i-1, 0) + w.del2; for (int j = 1; j != b_size; ++j) { if (a[i] == b[j]) { e(i, j) = e(i-1, j-1); } else { e(i, j) = w.sub + e(i-1, j-1); if (i != 1 && j != 1 && a[i] == b[j-1] && a[i-1] == b[j]) { te = w.swap + e(i-2, j-2); if (te < e(i, j)) e(i, j) = te; } te = w.del1 + e(i-1, j); if (te < e(i, j)) e(i, j) = te; te = w.del2 + e(i, j-1); if (te < e(i, j)) e(i, j) = te; } } } return e(a_size-1, b_size-1); }
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; }
void operator= (ParmString s) {str = s; size = s.size();}
PosibErr<bool> check(ParmString word) { std::vector<char> w(word.size()+1); strncpy(&*w.begin(), word, w.size()); return check(MutableString(&w.front(), w.size() - 1)); }