]> git.lyx.org Git - lyx.git/blobdiff - src/kbsequence.C
whitespace changes;
[lyx.git] / src / kbsequence.C
index 29b7d453b0ffdb1d62206291f25ea0a94fe91b08..7c661929c24b2dce3d9baa7c74cf1898a432cc4d 100644 (file)
@@ -4,12 +4,12 @@
  *           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"
@@ -87,23 +87,25 @@ int kb_sequence::addkey(unsigned int key,
     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;
@@ -120,7 +122,8 @@ int kb_sequence::parse(string const & s)
                        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;
@@ -140,7 +143,7 @@ int kb_sequence::parse(string const & s)
                } 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());
@@ -157,7 +160,13 @@ int kb_sequence::parse(string const & s)
                        nmod = 0;
                }
        }
-       return 0;
+       
+       // empty sequence?
+       if (!length)
+               return 0;
+
+       // everything is fine
+       return string::npos;
 }
 
 
@@ -262,8 +271,11 @@ char kb_sequence::getiso() const
 {
        unsigned int const c = getsym();
 
-       lyxerr << "Raw keysym: " << std::hex << c << std::dec << endl;
-       lyxerr << "byte 3: " << std::hex << (c & 0x0000FF00) << std::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