Convert the part of the keymap code that will not be removed to docstring.

This is purely mechanical, and touches only code that is currently not active.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17657 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2007-03-31 08:12:08 +00:00
parent c473aedee7
commit 0141fba79a
7 changed files with 96 additions and 97 deletions

View File

@ -14,13 +14,9 @@
#include "tex-accent.h" #include "tex-accent.h"
#include "support/convert.h" #include "support/convert.h"
#include <string>
namespace lyx { namespace lyx {
using std::string;
/* the names used by TeX and XWindows for deadkeys/accents are not the same /* 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 so here follows a table to clearify the differences. Please correct this
if I got it wrong 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 += lyx_accent_table[accent].cmd;
res += '{'; 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<string>(c), accent); return DoAccent(docstring(1, c), accent);
} }

View File

@ -14,6 +14,7 @@
#define TEX_ACCENT #define TEX_ACCENT
#include "lfuns.h" #include "lfuns.h"
#include "support/docstring.h"
namespace lyx { namespace lyx {
@ -111,6 +112,11 @@ struct tex_accent_struct {
/// ///
extern tex_accent_struct lyx_accent_table[]; 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 } // namespace lyx

View File

@ -48,8 +48,8 @@ Trans::~Trans()
} }
void Trans::insertException(KmodException & exclist, char c, void Trans::insertException(KmodException & exclist, char_type c,
string const & data, bool flag, tex_accent accent) docstring const & data, bool flag, tex_accent accent)
{ {
Keyexc p; Keyexc p;
p.c = c; p.c = c;
@ -107,17 +107,20 @@ struct keyword_item kmapTags[K_LAST - 1] = {
tex_accent getkeymod(string const &); 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; KmodInfo tmp;
tmp.data = keys; tmp.data = keys;
tmp.accent = accent; tmp.accent = accent;
kmod_list_[accent] = tmp; kmod_list_[accent] = tmp;
for (string::size_type i = 0; i < keys.length(); ++i) { for (docstring::size_type i = 0; i < keys.length(); ++i) {
string tmp; // FIXME This is a hack.
tmp += char(0); // tmp is no valid UCS4 string, but misused to store the
tmp += char(accent); // accent.
docstring tmp;
tmp += char_type(0);
tmp += char_type(accent);
keymap_[keys[i]] = tmp; keymap_[keys[i]] = tmp;
} }
} }
@ -140,7 +143,7 @@ int Trans::load(LyXLex & lex)
} else } else
return -1; return -1;
string const keys = lex.getString(); docstring const keys = lex.getDocString();
if (lex.next(true)) { if (lex.next(true)) {
if (lyxerr.debugging(Debug::KBMAP)) if (lyxerr.debugging(Debug::KBMAP))
@ -194,9 +197,9 @@ int Trans::load(LyXLex & lex)
tex_accent accent_2= getkeymod(str); tex_accent accent_2= getkeymod(str);
if (accent_2 == TEX_NOACCENT) return -1; if (accent_2 == TEX_NOACCENT) return -1;
map<int, KmodInfo>::iterator it1 = map<tex_accent, KmodInfo>::iterator it1 =
kmod_list_.find(accent_1); kmod_list_.find(accent_1);
map<int, KmodInfo>::iterator it2 = map<tex_accent, KmodInfo>::iterator it2 =
kmod_list_.find(accent_2); kmod_list_.find(accent_2);
if (it1 == kmod_list_.end() if (it1 == kmod_list_.end()
|| it2 == kmod_list_.end()) { || it2 == kmod_list_.end()) {
@ -205,25 +208,25 @@ int Trans::load(LyXLex & lex)
// Find what key accent_2 is on - should // Find what key accent_2 is on - should
// check about accent_1 also // check about accent_1 also
map<int, string>::iterator it = keymap_.begin(); map<char_type, docstring>::iterator it = keymap_.begin();
map<int, string>::iterator end = keymap_.end(); map<char_type, docstring>::iterator end = keymap_.end();
for (; it != end; ++it) { for (; it != end; ++it) {
if (!it->second.empty() if (!it->second.empty()
&& it->second[0] == 0 && it->second[0] == 0
&& it->second[1] == accent_2) && it->second[1] == accent_2)
break; break;
} }
string allowed; docstring allowed;
if (lex.next()) { if (lex.next()) {
allowed = lex.getString(); allowed = lex.getDocString();
lyxerr[Debug::KBMAP] << "allowed: " lyxerr[Debug::KBMAP] << "allowed: "
<< allowed << endl; << to_utf8(allowed) << endl;
} else { } else {
return -1; return -1;
} }
insertException(kmod_list_[accent_1].exception_list, insertException(kmod_list_[accent_1].exception_list,
static_cast<char>(it->first), allowed, it->first, allowed,
true, accent_2); true, accent_2);
} }
break; break;
@ -241,10 +244,10 @@ int Trans::load(LyXLex & lex)
return -1; return -1;
if (lex.next(true)) { if (lex.next(true)) {
string const string_to = lex.getString(); docstring const string_to = lex.getDocString();
keymap_[key_from] = string_to; keymap_[key_from] = string_to;
if (lyxerr.debugging(Debug::KBMAP)) if (lyxerr.debugging(Debug::KBMAP))
lyxerr << "\t`" << string_to << '\'' lyxerr << "\t`" << to_utf8(string_to) << '\''
<< endl; << endl;
} else } else
return -1; return -1;
@ -253,8 +256,8 @@ int Trans::load(LyXLex & lex)
} }
case KXMOD: { case KXMOD: {
tex_accent accent; tex_accent accent;
char key; char_type key;
string str; docstring str;
if (lyxerr.debugging(Debug::KBMAP)) if (lyxerr.debugging(Debug::KBMAP))
lyxerr << "KXMOD:\t" << lex.getString() << endl; lyxerr << "KXMOD:\t" << lex.getString() << endl;
@ -270,7 +273,7 @@ int Trans::load(LyXLex & lex)
if (lyxerr.debugging(Debug::KBMAP)) if (lyxerr.debugging(Debug::KBMAP))
lyxerr << "\t`" << lex.getString() << '\'' lyxerr << "\t`" << lex.getString() << '\''
<< endl; << endl;
key = lex.getString()[0]; key = lex.getDocString()[0];
} else } else
return -1; return -1;
@ -278,7 +281,7 @@ int Trans::load(LyXLex & lex)
if (lyxerr.debugging(Debug::KBMAP)) if (lyxerr.debugging(Debug::KBMAP))
lyxerr << "\t`" << lex.getString() << '\'' lyxerr << "\t`" << lex.getString() << '\''
<< endl; << endl;
str = lex.getString(); str = lex.getDocString();
} else } else
return -1; return -1;
@ -301,7 +304,7 @@ int Trans::load(LyXLex & lex)
bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const
{ {
map<int, KmodInfo>::const_iterator cit = kmod_list_.find(accent); map<tex_accent, KmodInfo>::const_iterator cit = kmod_list_.find(accent);
if (cit != kmod_list_.end()) { if (cit != kmod_list_.end()) {
i = cit->second; i = cit->second;
return true; 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<unsigned char>(c)); docstring const t = match(c);
if (t.empty() && c != 0) { if (t.empty() && c != 0) {
return k.normalkey(c); return k.normalkey(c);
} else if (!t.empty() && t[0] != char(0)) { } else if (!t.empty() && t[0] != 0) {
//return k.normalkey(c); //return k.normalkey(c);
return t; return t;
} else { } else {

View File

@ -43,22 +43,22 @@ public:
/// ///
std::string const & getName() const; std::string const & getName() const;
/// ///
std::string const process(char, TransManager &); docstring const process(char_type, TransManager &);
/// ///
bool isAccentDefined(tex_accent, KmodInfo &) const; bool isAccentDefined(tex_accent, KmodInfo &) const;
private: private:
/// ///
void addDeadkey(tex_accent, std::string const &); void addDeadkey(tex_accent, docstring const &);
/// ///
void freeKeymap(); void freeKeymap();
/// ///
int load(LyXLex &); int load(LyXLex &);
/// ///
std::string const & match(unsigned char c); docstring const & match(char_type c);
/// ///
void insertException(KmodException & exclist, char c, void insertException(KmodException & exclist, char_type c,
std::string const & data, bool = false, docstring const & data, bool = false,
tex_accent = TEX_NOACCENT); tex_accent = TEX_NOACCENT);
/// ///
void freeException(KmodException & exclist); void freeException(KmodException & exclist);
@ -66,21 +66,21 @@ private:
/// ///
std::string name_; std::string name_;
/// ///
std::map<int, std::string> keymap_; std::map<char_type, docstring> keymap_;
/// ///
std::map<int, KmodInfo> kmod_list_; std::map<tex_accent, KmodInfo> kmod_list_;
}; };
/// ///
inline inline
std::string const & Trans::match(unsigned char c) docstring const & Trans::match(char_type c)
{ {
std::map<int, std::string>::iterator it = keymap_.find(c); std::map<char_type, docstring>::iterator it = keymap_.find(c);
if (it != keymap_.end()) { if (it != keymap_.end()) {
return it->second; return it->second;
} }
static std::string dummy; static docstring dummy;
return dummy; return dummy;
} }

View File

@ -16,7 +16,6 @@
#include "tex-accent.h" #include "tex-accent.h"
#include <list> #include <list>
#include <string>
namespace lyx { namespace lyx {
@ -25,9 +24,9 @@ namespace lyx {
/// ///
struct Keyexc { struct Keyexc {
/// character to make exception /// character to make exception
char c; char_type c;
/// exception data /// exception data
std::string data; docstring data;
/// Combination with another deadkey /// Combination with another deadkey
bool combined; bool combined;
/// The accent comined with /// The accent comined with
@ -41,7 +40,7 @@ typedef std::list<Keyexc> KmodException;
class KmodInfo { class KmodInfo {
public: public:
/// ///
std::string data; docstring data;
/// ///
tex_accent accent; tex_accent accent;
/// ///

View File

@ -34,10 +34,6 @@ using std::string;
using std::pair; using std::pair;
extern string const DoAccent(string const &, tex_accent);
extern string const DoAccent(char, tex_accent);
// TransFSMData // TransFSMData
TransFSMData::TransFSMData() TransFSMData::TransFSMData()
{ {
@ -47,7 +43,7 @@ TransFSMData::TransFSMData()
// TransState // TransState
char const TransState::TOKEN_SEP = 4; char_type const TransState::TOKEN_SEP = 4;
// TransInitState // 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; res = c;
return res; return res;
} }
string const TransInitState::deadkey(char c, KmodInfo d) docstring const TransInitState::deadkey(char_type c, KmodInfo d)
{ {
deadkey_ = c; deadkey_ = c;
deadkey_info_ = d; deadkey_info_ = d;
currentState = deadkey_state_; 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 it = deadkey_info_.exception_list.begin();
KmodException::iterator end = deadkey_info_.exception_list.end(); 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 // Check if the same deadkey was typed twice
if (deadkey_ == c) { if (deadkey_ == c) {
@ -124,7 +120,7 @@ string const TransDeadkeyState::deadkey(char c, KmodInfo d)
deadkey2_info_ = d; deadkey2_info_ = d;
comb_info_ = (*cit); comb_info_ = (*cit);
currentState = combined_state_; currentState = combined_state_;
return string(); return docstring();
} }
if (cit->c == c) { if (cit->c == c) {
res = cit->data; 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); docstring const temp = DoAccent(c, deadkey2_info_.accent);
string const res = DoAccent(temp, deadkey_info_.accent); docstring const res = DoAccent(temp, deadkey_info_.accent);
currentState = init_state_; currentState = init_state_;
return res; 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 // Third key in a row. Output the first one and
// reenter with shifted deadkeys // reenter with shifted deadkeys
string res; docstring res;
if (deadkey_ != 0) if (deadkey_ != 0)
res = deadkey_; res = deadkey_;
res += TOKEN_SEP; 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 // Process with tokens
string temp; docstring temp;
while (res.length() > 0) { while (res.length() > 0) {
res = split(res, temp, TransState::TOKEN_SEP); 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) for (string::size_type i = 0, n = str.size(); i < n; ++i)
text->insertChar(cur, str[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 // Go through the character encoding only if the current
// encoding (chset_->name()) matches the current font_norm // 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 // Is false to speak about "only if" the current encoding will
// almost always be equal to font_norm. // almost always be equal to font_norm.
pair<bool, int> enc = chset_.encodeString(str); pair<bool, int> enc = chset_.encodeString(to_utf8(str));
if (chset_.getName() != lyxrc.font_norm || if (chset_.getName() != lyxrc.font_norm ||
!enc.first) { !enc.first) {
// Could not find an encoding // Could not find an encoding
insertVerbatim(str, text, cur); insertVerbatim(str, text, cur);
return; return;
} }
string const tmp(1, static_cast<char>(enc.second)); text->insertChar(cur, enc.second);
insertVerbatim(tmp, text, cur);
} }
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_) { if (c == 0 && active_ != &default_) {
// A deadkey was pressed that cannot be printed // A deadkey was pressed that cannot be printed
// or a accent command was typed in the minibuffer // or a accent command was typed in the minibuffer
KmodInfo i; KmodInfo i;
if (active_->isAccentDefined(accent, i) == true) { if (active_->isAccentDefined(accent, i) == true) {
string const res = trans_fsm_ docstring const res = trans_fsm_
.currentState->deadkey(c, i); .currentState->deadkey(c, i);
insert(res, t, cur); insert(res, t, cur);
return; return;
@ -311,7 +306,7 @@ void TransManager::deadkey(char c, tex_accent accent, LyXText * t, LCursor & cur
KmodInfo i; KmodInfo i;
i.accent = accent; i.accent = accent;
i.data.erase(); i.data.erase();
string res = trans_fsm_.currentState->deadkey(c, i); docstring res = trans_fsm_.currentState->deadkey(c, i);
insert(res, t, cur); insert(res, t, cur);
} else { } else {
// Go through the translation // Go through the translation

View File

@ -32,13 +32,13 @@ public:
/// ///
virtual ~TransState() {} virtual ~TransState() {}
/// ///
virtual std::string const normalkey(char) = 0; virtual docstring const normalkey(char_type) = 0;
/// ///
virtual bool backspace() = 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() {} virtual ~TransFSMData() {}
/// ///
char deadkey_; char_type deadkey_;
/// ///
KmodInfo deadkey_info_; KmodInfo deadkey_info_;
/// ///
char deadkey2_; char_type deadkey2_;
/// ///
KmodInfo deadkey2_info_; KmodInfo deadkey2_info_;
/// ///
@ -78,11 +78,11 @@ public:
/// ///
TransInitState(); TransInitState();
/// ///
virtual std::string const normalkey(char); virtual docstring const normalkey(char_type);
/// ///
virtual bool backspace() { return true; } 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(); TransDeadkeyState();
/// ///
virtual std::string const normalkey(char); virtual docstring const normalkey(char_type);
/// ///
virtual bool backspace() { virtual bool backspace() {
currentState = init_state_; currentState = init_state_;
return false; return false;
} }
/// ///
virtual std::string const deadkey(char, KmodInfo); virtual docstring const deadkey(char_type, KmodInfo);
}; };
@ -109,7 +109,7 @@ public:
/// ///
TransCombinedState(); TransCombinedState();
/// ///
virtual std::string const normalkey(char); virtual docstring const normalkey(char_type);
/// ///
virtual bool backspace() { virtual bool backspace() {
// cancel the second deadkey // cancel the second deadkey
@ -120,7 +120,7 @@ public:
return false; return false;
} }
/// ///
virtual std::string const deadkey(char, KmodInfo); virtual docstring const deadkey(char_type, KmodInfo);
}; };
@ -151,9 +151,9 @@ private:
/// ///
CharacterSet chset_; 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: public:
/// ///
TransManager(); TransManager();
@ -176,25 +176,25 @@ public:
return trans_fsm_.currentState->backspace(); 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 inline
std::string const TransManager::normalkey(char c) docstring const TransManager::normalkey(char_type c)
{ {
return trans_fsm_.currentState->normalkey(c); return trans_fsm_.currentState->normalkey(c);
} }
inline 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); return trans_fsm_.currentState->deadkey(c, t);
} }