summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2011-12-20 19:21:11 +0000
committerMaxime Coste <frrrwww@gmail.com>2011-12-20 19:21:11 +0000
commit42a24895de84f0bcaae6f04621dda07d30e0afdd (patch)
tree244622aa876204cedc5cb6ba7cf4e1a3ea837467 /src
parent91606850fdbea8a9c6d919b7ad90bd6643676f30 (diff)
Add Key struct
Diffstat (limited to 'src')
-rw-r--r--src/keys.cc40
-rw-r--r--src/keys.hh33
2 files changed, 73 insertions, 0 deletions
diff --git a/src/keys.cc b/src/keys.cc
new file mode 100644
index 00000000..bf6a4cdc
--- /dev/null
+++ b/src/keys.cc
@@ -0,0 +1,40 @@
+#include "keys.hh"
+
+#include <unordered_map>
+
+namespace Kakoune
+{
+
+static std::unordered_map<std::string, Key> keynamemap = {
+ { "ret", { Key::Modifiers::None, '\n' } }
+};
+
+KeyList parse_keys(const std::string& str)
+{
+ KeyList result;
+ for (size_t pos = 0; pos < str.length(); ++pos)
+ {
+ if (str[pos] == '<')
+ {
+ size_t end_pos = pos;
+ while (end_pos < str.length() and str[end_pos] != '>')
+ ++end_pos;
+
+ if (end_pos < str.length())
+ {
+ std::string keyname = str.substr(pos+1, end_pos - pos - 1);
+ auto it = keynamemap.find(keyname);
+ if (it != keynamemap.end())
+ {
+ result.push_back(it->second);
+ pos = end_pos;
+ continue;
+ }
+ }
+ }
+ result.push_back({Key::Modifiers::None, str[pos]});
+ }
+ return result;
+}
+
+}
diff --git a/src/keys.hh b/src/keys.hh
new file mode 100644
index 00000000..f28dc031
--- /dev/null
+++ b/src/keys.hh
@@ -0,0 +1,33 @@
+#ifndef keys_hh_INCLUDED
+#define keys_hh_INCLUDED
+
+#include <vector>
+#include <string>
+
+namespace Kakoune
+{
+
+struct Key
+{
+ enum class Modifiers
+ {
+ None = 0,
+ Control = 1,
+ Alt = 2,
+ ControlAlt = 3
+ };
+
+ Modifiers modifiers;
+ char key;
+
+ Key(Modifiers modifiers, char key)
+ : modifiers(modifiers), key(key) {}
+};
+
+typedef std::vector<Key> KeyList;
+
+KeyList parse_keys(const std::string& str);
+
+}
+
+#endif // keys_hh_INCLUDED