diff --git a/src/tex-accent.C b/src/tex-accent.C index 63e6185cb5..08c9444391 100644 --- a/src/tex-accent.C +++ b/src/tex-accent.C @@ -14,13 +14,9 @@ #include "tex-accent.h" #include "support/convert.h" -#include - namespace lyx { -using std::string; - /* the names used by TeX and XWindows for deadkeys/accents are not the same so here follows a table to clearify the differences. Please correct this if I got it wrong @@ -87,9 +83,9 @@ tex_accent_struct get_accent(kb_action action) } -string const DoAccent(string const & s, tex_accent accent) +docstring const DoAccent(docstring const & s, tex_accent accent) { - string res; + docstring res; res += lyx_accent_table[accent].cmd; res += '{'; @@ -102,9 +98,9 @@ string const DoAccent(string const & s, tex_accent accent) } -string const DoAccent(char c, tex_accent accent) +docstring const DoAccent(char_type c, tex_accent accent) { - return DoAccent(convert(c), accent); + return DoAccent(docstring(1, c), accent); } diff --git a/src/tex-accent.h b/src/tex-accent.h index 7f7ec3d533..d5b8f3058b 100644 --- a/src/tex-accent.h +++ b/src/tex-accent.h @@ -14,6 +14,7 @@ #define TEX_ACCENT #include "lfuns.h" +#include "support/docstring.h" namespace lyx { @@ -111,6 +112,11 @@ struct tex_accent_struct { /// extern tex_accent_struct lyx_accent_table[]; +/// +extern docstring const DoAccent(docstring const &, tex_accent); +/// +extern docstring const DoAccent(char_type, tex_accent); + } // namespace lyx diff --git a/src/trans.C b/src/trans.C index 13e5285973..083db5e7c2 100644 --- a/src/trans.C +++ b/src/trans.C @@ -48,8 +48,8 @@ Trans::~Trans() } -void Trans::insertException(KmodException & exclist, char c, - string const & data, bool flag, tex_accent accent) +void Trans::insertException(KmodException & exclist, char_type c, + docstring const & data, bool flag, tex_accent accent) { Keyexc p; p.c = c; @@ -107,17 +107,20 @@ struct keyword_item kmapTags[K_LAST - 1] = { tex_accent getkeymod(string const &); -void Trans::addDeadkey(tex_accent accent, string const & keys) +void Trans::addDeadkey(tex_accent accent, docstring const & keys) { KmodInfo tmp; tmp.data = keys; tmp.accent = accent; kmod_list_[accent] = tmp; - for (string::size_type i = 0; i < keys.length(); ++i) { - string tmp; - tmp += char(0); - tmp += char(accent); + for (docstring::size_type i = 0; i < keys.length(); ++i) { + // FIXME This is a hack. + // tmp is no valid UCS4 string, but misused to store the + // accent. + docstring tmp; + tmp += char_type(0); + tmp += char_type(accent); keymap_[keys[i]] = tmp; } } @@ -140,7 +143,7 @@ int Trans::load(LyXLex & lex) } else return -1; - string const keys = lex.getString(); + docstring const keys = lex.getDocString(); if (lex.next(true)) { if (lyxerr.debugging(Debug::KBMAP)) @@ -194,9 +197,9 @@ int Trans::load(LyXLex & lex) tex_accent accent_2= getkeymod(str); if (accent_2 == TEX_NOACCENT) return -1; - map::iterator it1 = + map::iterator it1 = kmod_list_.find(accent_1); - map::iterator it2 = + map::iterator it2 = kmod_list_.find(accent_2); if (it1 == kmod_list_.end() || it2 == kmod_list_.end()) { @@ -205,25 +208,25 @@ int Trans::load(LyXLex & lex) // Find what key accent_2 is on - should // check about accent_1 also - map::iterator it = keymap_.begin(); - map::iterator end = keymap_.end(); + map::iterator it = keymap_.begin(); + map::iterator end = keymap_.end(); for (; it != end; ++it) { if (!it->second.empty() && it->second[0] == 0 && it->second[1] == accent_2) break; } - string allowed; + docstring allowed; if (lex.next()) { - allowed = lex.getString(); + allowed = lex.getDocString(); lyxerr[Debug::KBMAP] << "allowed: " - << allowed << endl; + << to_utf8(allowed) << endl; } else { return -1; } insertException(kmod_list_[accent_1].exception_list, - static_cast(it->first), allowed, + it->first, allowed, true, accent_2); } break; @@ -241,10 +244,10 @@ int Trans::load(LyXLex & lex) return -1; if (lex.next(true)) { - string const string_to = lex.getString(); + docstring const string_to = lex.getDocString(); keymap_[key_from] = string_to; if (lyxerr.debugging(Debug::KBMAP)) - lyxerr << "\t`" << string_to << '\'' + lyxerr << "\t`" << to_utf8(string_to) << '\'' << endl; } else return -1; @@ -253,8 +256,8 @@ int Trans::load(LyXLex & lex) } case KXMOD: { tex_accent accent; - char key; - string str; + char_type key; + docstring str; if (lyxerr.debugging(Debug::KBMAP)) lyxerr << "KXMOD:\t" << lex.getString() << endl; @@ -270,7 +273,7 @@ int Trans::load(LyXLex & lex) if (lyxerr.debugging(Debug::KBMAP)) lyxerr << "\t`" << lex.getString() << '\'' << endl; - key = lex.getString()[0]; + key = lex.getDocString()[0]; } else return -1; @@ -278,7 +281,7 @@ int Trans::load(LyXLex & lex) if (lyxerr.debugging(Debug::KBMAP)) lyxerr << "\t`" << lex.getString() << '\'' << endl; - str = lex.getString(); + str = lex.getDocString(); } else return -1; @@ -301,7 +304,7 @@ int Trans::load(LyXLex & lex) bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const { - map::const_iterator cit = kmod_list_.find(accent); + map::const_iterator cit = kmod_list_.find(accent); if (cit != kmod_list_.end()) { i = cit->second; return true; @@ -310,13 +313,13 @@ bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const } -string const Trans::process(char c, TransManager & k) +docstring const Trans::process(char_type c, TransManager & k) { - string const t = match(static_cast(c)); + docstring const t = match(c); if (t.empty() && c != 0) { return k.normalkey(c); - } else if (!t.empty() && t[0] != char(0)) { + } else if (!t.empty() && t[0] != 0) { //return k.normalkey(c); return t; } else { diff --git a/src/trans.h b/src/trans.h index ce529a2b9f..2db65e41c0 100644 --- a/src/trans.h +++ b/src/trans.h @@ -43,22 +43,22 @@ public: /// std::string const & getName() const; /// - std::string const process(char, TransManager &); + docstring const process(char_type, TransManager &); /// bool isAccentDefined(tex_accent, KmodInfo &) const; private: /// - void addDeadkey(tex_accent, std::string const &); + void addDeadkey(tex_accent, docstring const &); /// void freeKeymap(); /// int load(LyXLex &); /// - std::string const & match(unsigned char c); + docstring const & match(char_type c); /// - void insertException(KmodException & exclist, char c, - std::string const & data, bool = false, + void insertException(KmodException & exclist, char_type c, + docstring const & data, bool = false, tex_accent = TEX_NOACCENT); /// void freeException(KmodException & exclist); @@ -66,21 +66,21 @@ private: /// std::string name_; /// - std::map keymap_; + std::map keymap_; /// - std::map kmod_list_; + std::map kmod_list_; }; /// inline -std::string const & Trans::match(unsigned char c) +docstring const & Trans::match(char_type c) { - std::map::iterator it = keymap_.find(c); + std::map::iterator it = keymap_.find(c); if (it != keymap_.end()) { return it->second; } - static std::string dummy; + static docstring dummy; return dummy; } diff --git a/src/trans_decl.h b/src/trans_decl.h index 9d6aa5b467..f3704ab3d0 100644 --- a/src/trans_decl.h +++ b/src/trans_decl.h @@ -16,7 +16,6 @@ #include "tex-accent.h" #include -#include namespace lyx { @@ -25,9 +24,9 @@ namespace lyx { /// struct Keyexc { /// character to make exception - char c; + char_type c; /// exception data - std::string data; + docstring data; /// Combination with another deadkey bool combined; /// The accent comined with @@ -41,7 +40,7 @@ typedef std::list KmodException; class KmodInfo { public: /// - std::string data; + docstring data; /// tex_accent accent; /// diff --git a/src/trans_mgr.C b/src/trans_mgr.C index d3fb833abc..73c79b4ed6 100644 --- a/src/trans_mgr.C +++ b/src/trans_mgr.C @@ -34,10 +34,6 @@ using std::string; using std::pair; -extern string const DoAccent(string const &, tex_accent); -extern string const DoAccent(char, tex_accent); - - // TransFSMData TransFSMData::TransFSMData() { @@ -47,7 +43,7 @@ TransFSMData::TransFSMData() // TransState -char const TransState::TOKEN_SEP = 4; +char_type const TransState::TOKEN_SEP = 4; // TransInitState @@ -57,20 +53,20 @@ TransInitState::TransInitState() } -string const TransInitState::normalkey(char c) +docstring const TransInitState::normalkey(char_type c) { - string res; + docstring res; res = c; return res; } -string const TransInitState::deadkey(char c, KmodInfo d) +docstring const TransInitState::deadkey(char_type c, KmodInfo d) { deadkey_ = c; deadkey_info_ = d; currentState = deadkey_state_; - return string(); + return docstring(); } @@ -81,9 +77,9 @@ TransDeadkeyState::TransDeadkeyState() } -string const TransDeadkeyState::normalkey(char c) +docstring const TransDeadkeyState::normalkey(char_type c) { - string res; + docstring res; KmodException::iterator it = deadkey_info_.exception_list.begin(); KmodException::iterator end = deadkey_info_.exception_list.end(); @@ -102,9 +98,9 @@ string const TransDeadkeyState::normalkey(char c) } -string const TransDeadkeyState::deadkey(char c, KmodInfo d) +docstring const TransDeadkeyState::deadkey(char_type c, KmodInfo d) { - string res; + docstring res; // Check if the same deadkey was typed twice if (deadkey_ == c) { @@ -124,7 +120,7 @@ string const TransDeadkeyState::deadkey(char c, KmodInfo d) deadkey2_info_ = d; comb_info_ = (*cit); currentState = combined_state_; - return string(); + return docstring(); } if (cit->c == c) { res = cit->data; @@ -153,20 +149,20 @@ TransCombinedState::TransCombinedState() } -string const TransCombinedState::normalkey(char c) +docstring const TransCombinedState::normalkey(char_type c) { - string const temp = DoAccent(c, deadkey2_info_.accent); - string const res = DoAccent(temp, deadkey_info_.accent); + docstring const temp = DoAccent(c, deadkey2_info_.accent); + docstring const res = DoAccent(temp, deadkey_info_.accent); currentState = init_state_; return res; } -string const TransCombinedState::deadkey(char c, KmodInfo d) +docstring const TransCombinedState::deadkey(char_type c, KmodInfo d) { // Third key in a row. Output the first one and // reenter with shifted deadkeys - string res; + docstring res; if (deadkey_ != 0) res = deadkey_; res += TOKEN_SEP; @@ -252,12 +248,12 @@ void TransManager::disableKeymap() } -void TransManager::translateAndInsert(char c, LyXText * text, LCursor & cur) +void TransManager::translateAndInsert(char_type c, LyXText * text, LCursor & cur) { - string res = active_->process(c, *this); + docstring res = active_->process(c, *this); // Process with tokens - string temp; + docstring temp; while (res.length() > 0) { res = split(res, temp, TransState::TOKEN_SEP); @@ -266,14 +262,14 @@ void TransManager::translateAndInsert(char c, LyXText * text, LCursor & cur) } -void TransManager::insertVerbatim(string const & str, LyXText * text, LCursor & cur) +void TransManager::insertVerbatim(docstring const & str, LyXText * text, LCursor & cur) { for (string::size_type i = 0, n = str.size(); i < n; ++i) text->insertChar(cur, str[i]); } -void TransManager::insert(string const & str, LyXText * text, LCursor & cur) +void TransManager::insert(docstring const & str, LyXText * text, LCursor & cur) { // Go through the character encoding only if the current // encoding (chset_->name()) matches the current font_norm @@ -281,26 +277,25 @@ void TransManager::insert(string const & str, LyXText * text, LCursor & cur) // Is false to speak about "only if" the current encoding will // almost always be equal to font_norm. - pair enc = chset_.encodeString(str); + pair enc = chset_.encodeString(to_utf8(str)); if (chset_.getName() != lyxrc.font_norm || !enc.first) { // Could not find an encoding insertVerbatim(str, text, cur); return; } - string const tmp(1, static_cast(enc.second)); - insertVerbatim(tmp, text, cur); + text->insertChar(cur, enc.second); } -void TransManager::deadkey(char c, tex_accent accent, LyXText * t, LCursor & cur) +void TransManager::deadkey(char_type c, tex_accent accent, LyXText * t, LCursor & cur) { if (c == 0 && active_ != &default_) { // A deadkey was pressed that cannot be printed // or a accent command was typed in the minibuffer KmodInfo i; if (active_->isAccentDefined(accent, i) == true) { - string const res = trans_fsm_ + docstring const res = trans_fsm_ .currentState->deadkey(c, i); insert(res, t, cur); return; @@ -311,7 +306,7 @@ void TransManager::deadkey(char c, tex_accent accent, LyXText * t, LCursor & cur KmodInfo i; i.accent = accent; i.data.erase(); - string res = trans_fsm_.currentState->deadkey(c, i); + docstring res = trans_fsm_.currentState->deadkey(c, i); insert(res, t, cur); } else { // Go through the translation diff --git a/src/trans_mgr.h b/src/trans_mgr.h index 06e98991eb..a9d5171240 100644 --- a/src/trans_mgr.h +++ b/src/trans_mgr.h @@ -32,13 +32,13 @@ public: /// virtual ~TransState() {} /// - virtual std::string const normalkey(char) = 0; + virtual docstring const normalkey(char_type) = 0; /// virtual bool backspace() = 0; /// - virtual std::string const deadkey(char, KmodInfo) = 0; + virtual docstring const deadkey(char_type, KmodInfo) = 0; /// - static char const TOKEN_SEP; + static char_type const TOKEN_SEP; }; @@ -48,11 +48,11 @@ protected: /// virtual ~TransFSMData() {} /// - char deadkey_; + char_type deadkey_; /// KmodInfo deadkey_info_; /// - char deadkey2_; + char_type deadkey2_; /// KmodInfo deadkey2_info_; /// @@ -78,11 +78,11 @@ public: /// TransInitState(); /// - virtual std::string const normalkey(char); + virtual docstring const normalkey(char_type); /// virtual bool backspace() { return true; } /// - virtual std::string const deadkey(char, KmodInfo); + virtual docstring const deadkey(char_type, KmodInfo); }; @@ -92,14 +92,14 @@ public: /// TransDeadkeyState(); /// - virtual std::string const normalkey(char); + virtual docstring const normalkey(char_type); /// virtual bool backspace() { currentState = init_state_; return false; } /// - virtual std::string const deadkey(char, KmodInfo); + virtual docstring const deadkey(char_type, KmodInfo); }; @@ -109,7 +109,7 @@ public: /// TransCombinedState(); /// - virtual std::string const normalkey(char); + virtual docstring const normalkey(char_type); /// virtual bool backspace() { // cancel the second deadkey @@ -120,7 +120,7 @@ public: return false; } /// - virtual std::string const deadkey(char, KmodInfo); + virtual docstring const deadkey(char_type, KmodInfo); }; @@ -151,9 +151,9 @@ private: /// CharacterSet chset_; /// - void insert(std::string const &, LyXText *, LCursor & cur); + void insert(docstring const &, LyXText *, LCursor & cur); /// - void insertVerbatim(std::string const &, LyXText *, LCursor & cur); + void insertVerbatim(docstring const &, LyXText *, LCursor & cur); public: /// TransManager(); @@ -176,25 +176,25 @@ public: return trans_fsm_.currentState->backspace(); } /// - void translateAndInsert(char, LyXText *, LCursor &); + void translateAndInsert(char_type, LyXText *, LCursor &); /// - std::string const deadkey(char, KmodInfo); + docstring const deadkey(char_type, KmodInfo); /// - std::string const normalkey(char); + docstring const normalkey(char_type); /// - void deadkey(char, tex_accent, LyXText *, LCursor &); + void deadkey(char_type, tex_accent, LyXText *, LCursor &); }; inline -std::string const TransManager::normalkey(char c) +docstring const TransManager::normalkey(char_type c) { return trans_fsm_.currentState->normalkey(c); } inline -std::string const TransManager::deadkey(char c, KmodInfo t) +docstring const TransManager::deadkey(char_type c, KmodInfo t) { return trans_fsm_.currentState->deadkey(c, t); }