#include "tex-accent.h"
#include "support/convert.h"
-#include <string>
-
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
}
-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 += '{';
}
-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);
}
#define TEX_ACCENT
#include "lfuns.h"
+#include "support/docstring.h"
namespace lyx {
///
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
}
-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;
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;
}
}
} else
return -1;
- string const keys = lex.getString();
+ docstring const keys = lex.getDocString();
if (lex.next(true)) {
if (lyxerr.debugging(Debug::KBMAP))
tex_accent accent_2= getkeymod(str);
if (accent_2 == TEX_NOACCENT) return -1;
- map<int, KmodInfo>::iterator it1 =
+ map<tex_accent, KmodInfo>::iterator it1 =
kmod_list_.find(accent_1);
- map<int, KmodInfo>::iterator it2 =
+ map<tex_accent, KmodInfo>::iterator it2 =
kmod_list_.find(accent_2);
if (it1 == kmod_list_.end()
|| it2 == kmod_list_.end()) {
// Find what key accent_2 is on - should
// check about accent_1 also
- map<int, string>::iterator it = keymap_.begin();
- map<int, string>::iterator end = keymap_.end();
+ map<char_type, docstring>::iterator it = keymap_.begin();
+ map<char_type, docstring>::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<char>(it->first), allowed,
+ it->first, allowed,
true, accent_2);
}
break;
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;
}
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;
if (lyxerr.debugging(Debug::KBMAP))
lyxerr << "\t`" << lex.getString() << '\''
<< endl;
- key = lex.getString()[0];
+ key = lex.getDocString()[0];
} else
return -1;
if (lyxerr.debugging(Debug::KBMAP))
lyxerr << "\t`" << lex.getString() << '\''
<< endl;
- str = lex.getString();
+ str = lex.getDocString();
} else
return -1;
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()) {
i = cit->second;
return true;
}
-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) {
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 {
///
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);
///
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
-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()) {
return it->second;
}
- static std::string dummy;
+ static docstring dummy;
return dummy;
}
#include "tex-accent.h"
#include <list>
-#include <string>
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
class KmodInfo {
public:
///
- std::string data;
+ docstring data;
///
tex_accent accent;
///
using std::pair;
-extern string const DoAccent(string const &, tex_accent);
-extern string const DoAccent(char, tex_accent);
-
-
// TransFSMData
TransFSMData::TransFSMData()
{
// TransState
-char const TransState::TOKEN_SEP = 4;
+char_type const TransState::TOKEN_SEP = 4;
// 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();
}
}
-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();
}
-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) {
deadkey2_info_ = d;
comb_info_ = (*cit);
currentState = combined_state_;
- return string();
+ return docstring();
}
if (cit->c == c) {
res = cit->data;
}
-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;
}
-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);
}
-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
// Is false to speak about "only if" the current encoding will
// 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 ||
!enc.first) {
// Could not find an encoding
insertVerbatim(str, text, cur);
return;
}
- string const tmp(1, static_cast<char>(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;
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
///
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;
};
///
virtual ~TransFSMData() {}
///
- char deadkey_;
+ char_type deadkey_;
///
KmodInfo deadkey_info_;
///
- char deadkey2_;
+ char_type deadkey2_;
///
KmodInfo deadkey2_info_;
///
///
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);
};
///
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);
};
///
TransCombinedState();
///
- virtual std::string const normalkey(char);
+ virtual docstring const normalkey(char_type);
///
virtual bool backspace() {
// cancel the second deadkey
return false;
}
///
- virtual std::string const deadkey(char, KmodInfo);
+ virtual docstring const deadkey(char_type, KmodInfo);
};
///
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();
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);
}