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 + +namespace Kakoune +{ + +static std::unordered_map 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 +#include + +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 KeyList; + +KeyList parse_keys(const std::string& str); + +} + +#endif // keys_hh_INCLUDED