Store key names in a constexpr array

This commit is contained in:
Maxime Coste 2014-03-20 19:52:11 +00:00
parent 0cdeb55968
commit 2cdf578834

View File

@ -16,8 +16,8 @@ Key canonicalize_ifn(Key key)
return key; return key;
} }
using KeyAndName = std::pair<String, Codepoint>; using KeyAndName = std::pair<const char*, Codepoint>;
static std::vector<KeyAndName> keynamemap = { static constexpr KeyAndName keynamemap[] = {
{ "ret", '\r' }, { "ret", '\r' },
{ "space", ' ' }, { "space", ' ' },
{ "tab", '\t' }, { "tab", '\t' },
@ -73,7 +73,7 @@ KeyList parse_keys(const String& str)
} }
auto it = find_if(keynamemap, [&keyname](const KeyAndName& item) auto it = find_if(keynamemap, [&keyname](const KeyAndName& item)
{ return item.first == keyname; }); { return item.first == keyname; });
if (it != keynamemap.end()) if (it != end(keynamemap))
{ {
Key key = canonicalize_ifn(Key{ modifier, it->second }); Key key = canonicalize_ifn(Key{ modifier, it->second });
result.push_back(key); result.push_back(key);
@ -116,7 +116,7 @@ String key_to_str(Key key)
String res; String res;
auto it = find_if(keynamemap, [&key](const KeyAndName& item) auto it = find_if(keynamemap, [&key](const KeyAndName& item)
{ return item.second == key.key; }); { return item.second == key.key; });
if (it != keynamemap.end()) if (it != end(keynamemap))
{ {
named = true; named = true;
res = it->first; res = it->first;