// // Copyright RIME Developers // Distributed under the BSD License // // 2011-11-21 GONG Chen // #ifndef RIME_PUNCTUATOR_H_ #define RIME_PUNCTUATOR_H_ #include #include #include #include #include #include #include namespace rime { class Engine; class PunctConfig { public: void LoadConfig(Engine* engine, bool load_symbols = false); an GetPunctDefinition(const string key); bool has_digit_separators() const { return !digit_separators_.empty(); } bool is_digit_separator(char ch) const { return digit_separators_.find(ch) != string::npos; } bool digit_separator_commit() const { return digit_separator_commit_; } protected: string shape_; an mapping_; an symbols_; string digit_separators_ = ".:"; bool digit_separator_commit_ = false; }; class Punctuator : public Processor { public: Punctuator(const Ticket& ticket); virtual ProcessResult ProcessKeyEvent(const KeyEvent& key_event); protected: bool ConvertDigitSeparator(char ch); bool ReconvertDigitSeparatorAsPunct(const string& key); bool AlternatePunct(const string& key, const an& definition); bool ConfirmUniquePunct(const an& definition); bool AutoCommitPunct(const an& definition); bool PairPunct(const an& definition); PunctConfig config_; bool use_space_ = false; map, int> oddness_; }; class PunctSegmentor : public Segmentor { public: PunctSegmentor(const Ticket& ticket); virtual bool Proceed(Segmentation* segmentation); protected: PunctConfig config_; }; class PunctTranslator : public Translator { public: PunctTranslator(const Ticket& ticket); virtual an Query(const string& input, const Segment& segment); protected: an TranslateUniquePunct(const string& key, const Segment& segment, const an& definition); an TranslateAlternatingPunct(const string& key, const Segment& segment, const an& definition); an TranslateAutoCommitPunct(const string& key, const Segment& segment, const an& definition); an TranslatePairedPunct(const string& key, const Segment& segment, const an& definition); ShapeFormatter formatter_; PunctConfig config_; }; } // namespace rime #endif // RIME_PUNCTUATOR_H_