⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 speller_impl.cpp

📁 unix/linux下拼写检查程序源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    DataSetCollection::Iterator to_del = wls_->locate(w);    if (to_del == wls_->wordlists_.end()) return false;    assert(to_del->own);    delete to_del->data_set;    wls_->wordlists_.erase(to_del);    return true;  }  void SpellerImpl::change_id(const DataSet::Id & w , SpecialId id) {    DataSetCollection::Iterator to_change = wls_->locate(w);    assert(to_change != wls_->end());    assert (id == none_id || !have(id));        switch (id) {    case main_id:      if (dynamic_cast<BasicWordSet *>(to_change->data_set)) {	to_change->use_to_check    = true;	to_change->use_to_suggest  = true;	to_change->save_on_saveall = false;      } else if (dynamic_cast<BasicMultiSet *>(to_change->data_set)) {		to_change->use_to_check    = false;	to_change->use_to_suggest  = false;	to_change->save_on_saveall = false;	      } else {		abort();	      }      break;    case personal_id:      assert(dynamic_cast<WritableWordSet *>(to_change->data_set));      to_change->use_to_check = true;      to_change->use_to_suggest = true;      to_change->save_on_saveall = true;      break;    case session_id:      assert(dynamic_cast<WritableWordSet *>(to_change->data_set));      to_change->use_to_check = true;      to_change->use_to_suggest = true;      to_change->save_on_saveall = false;      break;    case personal_repl_id:      assert (dynamic_cast<BasicReplacementSet *>(to_change->data_set));      to_change->use_to_check = false;      to_change->use_to_suggest = true;      to_change->save_on_saveall = config_->retrieve_bool("save-repl");      break;    case none_id:      break;    }    to_change->special_id = id;  }  //////////////////////////////////////////////////////////////////////  //  // Config Notifier  //  struct UpdateMember {    const char * name;    enum Type {String, Int, Bool, Add, Rem, RemAll};    Type type;    union Fun {      typedef PosibErr<void> (*WithStr )(SpellerImpl *, const char *);      typedef PosibErr<void> (*WithInt )(SpellerImpl *, int);      typedef PosibErr<void> (*WithBool)(SpellerImpl *, bool);      WithStr  with_str;      WithInt  with_int;      WithBool with_bool;      Fun() {}      Fun(WithStr  m) : with_str (m) {}      Fun(WithInt  m) : with_int (m) {}      Fun(WithBool m) : with_bool(m) {}      PosibErr<void> call(SpellerImpl * m, const char * val) const 	{return (*with_str) (m,val);}      PosibErr<void> call(SpellerImpl * m, int val)          const 	{return (*with_int) (m,val);}      PosibErr<void> call(SpellerImpl * m, bool val)         const 	{return (*with_bool)(m,val);}    } fun;    typedef SpellerImpl::ConfigNotifier CN;  };  template <typename T>  PosibErr<void> callback(SpellerImpl * m, const KeyInfo * ki, T value, 			  UpdateMember::Type t);    class SpellerImpl::ConfigNotifier : public Notifier {  private:    SpellerImpl * speller_;  public:    ConfigNotifier(SpellerImpl * m)       : speller_(m)     {}    PosibErr<void> item_updated(const KeyInfo * ki, int value) {      return callback(speller_, ki, value, UpdateMember::Int);    }    PosibErr<void> item_updated(const KeyInfo * ki, bool value) {      return callback(speller_, ki, value, UpdateMember::Bool);    }    PosibErr<void> item_updated(const KeyInfo * ki, ParmString value) {      return callback(speller_, ki, value, UpdateMember::String);    }    static PosibErr<void> ignore(SpellerImpl * m, int value) {      m->ignore_count = value;      return no_err;    }    static PosibErr<void> ignore_accents(SpellerImpl * m, bool value) {      abort(); return no_err;    }    static PosibErr<void> ignore_case(SpellerImpl * m, bool value) {      abort(); return no_err;    }    static PosibErr<void> ignore_repl(SpellerImpl * m, bool value) {      m->ignore_repl = value;      return no_err;    }    static PosibErr<void> save_repl(SpellerImpl * m, bool value) {      // FIXME      // m->save_on_saveall(DataSet::Id(&m->personal_repl()), value);      abort(); return no_err;    }    static PosibErr<void> sug_mode(SpellerImpl * m, const char * mode) {      RET_ON_ERR(m->suggest_->set_mode(mode));      RET_ON_ERR(m->intr_suggest_->set_mode(mode));      return no_err;    }    static PosibErr<void> run_together(SpellerImpl * m, bool value) {      m->unconditional_run_together_ = value;      return no_err;    }    static PosibErr<void> run_together_limit(SpellerImpl * m, int value) {      if (value > 8) {	m->config()->replace("run-together-limit", "8");	// will loop back      } else {	m->run_together_limit_ = value;      }      return no_err;    }    static PosibErr<void> run_together_min(SpellerImpl * m, int value) {      m->run_together_min_ = value;      if (m->unconditional_run_together_ 	  && m->run_together_min_ < m->run_together_start_len_)	m->run_together_start_len_ = m->run_together_min_;      return no_err;    }      };  static UpdateMember update_members[] =   {    {"ignore",         UpdateMember::Int,     UpdateMember::CN::ignore}    ,{"ignore-accents",UpdateMember::Bool,    UpdateMember::CN::ignore_accents}    ,{"ignore-case",   UpdateMember::Bool,    UpdateMember::CN::ignore_case}    ,{"ignore-repl",   UpdateMember::Bool,    UpdateMember::CN::ignore_repl}    ,{"save-repl",     UpdateMember::Bool,    UpdateMember::CN::save_repl}    ,{"sug-mode",      UpdateMember::String,  UpdateMember::CN::sug_mode}    ,{"run-together",  	UpdateMember::Bool,    	UpdateMember::CN::run_together}    ,{"run-together-limit",  	UpdateMember::Int,    	UpdateMember::CN::run_together_limit}    ,{"run-together-min",  	UpdateMember::Int,    	UpdateMember::CN::run_together_min}  };  template <typename T>  PosibErr<void> callback(SpellerImpl * m, const KeyInfo * ki, T value, 			  UpdateMember::Type t)   {    const UpdateMember * i      = update_members;    const UpdateMember * end         = i + sizeof(update_members)/sizeof(UpdateMember);    while (i != end) {      if (strcmp(ki->name, i->name) == 0) {	if (i->type == t) {	  RET_ON_ERR(i->fun.call(m, value));	  break;	}      }      ++i;    }    return no_err;  }  //////////////////////////////////////////////////////////////////////  //  // SpellerImpl inititization members  //  SpellerImpl::SpellerImpl()     : Speller(0) /* FIXME */, ignore_repl(true)  {}  PosibErr<void> SpellerImpl::setup(Config * c) {    assert (config_ == 0);    config_.reset(c);    ignore_repl = config_->retrieve_bool("ignore-repl");    ignore_count = config_->retrieve_int("ignore");    wls_.reset(new DataSetCollection());    RET_ON_ERR_SET(add_data_set(config_->retrieve("master-path"), *config_, this),		   LoadableDataSet *, ltemp);        change_id(ltemp, main_id);    StringList extra_dicts;    config_->retrieve_list("extra-dicts", &extra_dicts);    StringListEnumeration els = extra_dicts.elements_obj();    const char * dict_name;    while ( (dict_name = els.next()) != 0)      RET_ON_ERR(add_data_set(dict_name,*config_, this));        {      BasicWordSet * temp;      temp = new_default_writable_word_set();      PosibErrBase pe = temp->load(config_->retrieve("personal-path"),config_);      if (pe.has_err(cant_read_file))	temp->set_check_lang(lang_name(), config_);      else if (pe.has_err())	return pe;      steal(temp);      change_id(temp, personal_id);    }        {      BasicWordSet * temp;      temp = new_default_writable_word_set();      temp->set_check_lang(lang_name(), config_);      steal(temp);      change_id(temp, session_id);    }         {      BasicReplacementSet * temp = new_default_writable_replacement_set();      PosibErrBase pe = temp->load(config_->retrieve("repl-path"),config_);      if (pe.has_err(cant_read_file))	temp->set_check_lang(lang_name(), config_);      else if (pe.has_err())	return pe;      steal(temp);      change_id(temp, personal_repl_id);    }    const char * sys_enc = lang_->charset();    if (!config_->have("encoding"))      config_->replace("encoding", sys_enc);    String user_enc = config_->retrieve("encoding");    PosibErr<Convert *> conv;    conv = new_convert(*c, user_enc, sys_enc);    if (conv.has_err()) return conv;    to_internal_.reset(conv);    conv = new_convert(*c, sys_enc, user_enc);    if (conv.has_err()) return conv;    from_internal_.reset(conv);    unconditional_run_together_ = config_->retrieve_bool("run-together");    run_together_specified_     = config_->retrieve_bool("run-together-specified");    run_together_middle_        = lang().mid_chars();    run_together_limit_  = config_->retrieve_int("run-together-limit");    if (run_together_limit_ > 8) {      config_->replace("run-together-limit", "8");      run_together_limit_ = 8;    }    run_together_min_    = config_->retrieve_int("run-together-min");    run_together_start_len_ = config_->retrieve_int("run-together-specified");    if (unconditional_run_together_ 	&& run_together_min_ < run_together_start_len_)      run_together_start_len_ = run_together_min_;          suggest_.reset(new_default_suggest(this));    intr_suggest_.reset(new_default_suggest(this));    config_->add_notifier(new ConfigNotifier(this));    config_->set_attached(true);    return no_err;  }  //////////////////////////////////////////////////////////////////////  //  // SpellerImpl destrution members  //  SpellerImpl::~SpellerImpl() {    DataSetCollection::Iterator i   = wls_->begin();    DataSetCollection::Iterator end = wls_->end();    for (; i != end; ++i) {      if (i->own && i->data_set)	delete i->data_set;    }  }  //////////////////////////////////////////////////////////////////////  //  // SpellerImple setup tokenizer method  //  void SpellerImpl::setup_tokenizer(Tokenizer * tok)  {    for (int i = 0; i != 256; ++i)     {      tok->char_type_[i].word   = lang_->is_alpha(i);      tok->char_type_[i].begin  = lang_->special(i).begin;      tok->char_type_[i].middle = lang_->special(i).middle;      tok->char_type_[i].end    = lang_->special(i).end;    }    tok->conv_ = to_internal_;  }  //////////////////////////////////////////////////////////////////////  //  //  //  void SpellerImpl::DataSetCollection::Item::set_sensible_defaults()  {    switch (data_set->basic_type) {    case DataSet::basic_word_set:      use_to_check = true;      use_to_suggest = true;      break;    case DataSet::basic_replacement_set:      use_to_check = false;      use_to_suggest = true;    case DataSet::basic_multi_set:      break;    default:      abort();    }  }  extern "C"  Speller * libaspell_speller_default_LTX_new_speller_class(SpellerLtHandle)  {    return new SpellerImpl();  }}namespace acommon {  template class CopyPtr<aspeller::Language>;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -