* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
- * Copyright 1995-2000 The LyX Team.
+ * Copyright 1995-2001 The LyX Team.
*
* ====================================================== */
#include <config.h>
-#include <cstring>
+//#include <cstring>
#include <X11/Xlib.h>
#include "gettext.h"
Called by : [user]
Purpose : parse a string that holds a key sequence and add the keys
Parameters: s - string holding the key sequence
- Returns : 0 - if ok, error pos if error
+ Returns : string::npos if ok, error pos if error
Note : Keys must be separated with whitespace;
Use the keysym names used by XStringToKeysym
Prefixes are S-, C-, M- for shift, control, meta
\* ---F------------------------------------------------------------------- */
-int kb_sequence::parse(string const & s)
+string::size_type kb_sequence::parse(string const & s)
{
if (s.empty()) return 1;
string::size_type i = 0;
unsigned int mod = 0, nmod = 0;
while (i < s.length()) {
- if (s[i] && (s[i]) <= ' ') ++i;
- if (i >= s.length()) break;
+ if (s[i] == ' ')
+ ++i;
+ if (i >= s.length())
+ break;
- if (s[i + 1] == '-') { // is implicit that s[i] == true
+ if (i + 1 < s.length() && s[i + 1] == '-') {
switch (s[i]) {
case 's': case 'S':
mod |= ShiftMask;
default:
return i + 1;
}
- } else if (s[i] == '~' && s[i + 1] && s[i + 2] == '-') {
+ } else if (i + 2 < s.length() && s[i] == '~'
+ && s[i + 2] == '-') {
switch (s[i + 1]) {
case 's': case 'S':
nmod |= ShiftMask;
} else {
string tbuf;
string::size_type j = i;
- for (; j < s.length() && s[j] > ' '; ++j)
+ for (; j < s.length() && s[j] != ' '; ++j)
tbuf += s[j]; // (!!!check bounds :-)
KeySym key = XStringToKeysym(tbuf.c_str());
nmod = 0;
}
}
- return 0;
+
+ // empty sequence?
+ if (!length)
+ return 0;
+
+ // everything is fine
+ return string::npos;
}
{
unsigned int const c = getsym();
- lyxerr << "Raw keysym: " << hex << c << dec << endl;
- lyxerr << "byte 3: " << hex << (c & 0x0000FF00) << dec << endl;
+ lyxerr[Debug::KBMAP] << "Raw keysym: "
+ << std::hex << c << std::dec << endl;
+ lyxerr[Debug::KBMAP] << "byte 3: "
+ << std::hex << (c & 0x0000FF00) << std::dec
+ << endl;
switch (c & 0x0000FF00) {
// latin 1 byte 3 = 0
}
// not a latin char we know of
- return '\0';
+ // Yes but this is already handled above (JMarc)
+ //return '\0';
}