| 1106 | } |
| 1107 | |
| 1108 | bool KeyMap::parseKey(const std::string &x, KeyID &key) |
| 1109 | { |
| 1110 | // initialize tables |
| 1111 | initKeyNameMaps(); |
| 1112 | |
| 1113 | // parse the key |
| 1114 | key = kKeyNone; |
| 1115 | if (s_nameToKeyMap->contains(x)) { |
| 1116 | key = s_nameToKeyMap->find(x)->second; |
| 1117 | } |
| 1118 | // XXX -- we're assuming ASCII encoding here |
| 1119 | else if (x.size() == 1) { |
| 1120 | if (!isgraph(x[0])) { |
| 1121 | // unknown key |
| 1122 | return false; |
| 1123 | } |
| 1124 | key = (KeyID)x[0]; |
| 1125 | } else if (x.size() == 6 && x[0] == '\\' && x[1] == 'u') { |
| 1126 | // escaped unicode (\uXXXX where XXXX is a hex number) |
| 1127 | char *end; |
| 1128 | key = (KeyID)strtol(x.c_str() + 2, &end, 16); |
| 1129 | if (*end != '\0') { |
| 1130 | return false; |
| 1131 | } |
| 1132 | } else if (!x.empty()) { |
| 1133 | // unknown key |
| 1134 | return false; |
| 1135 | } |
| 1136 | |
| 1137 | return true; |
| 1138 | } |
| 1139 | |
| 1140 | bool KeyMap::parseModifiers(std::string &x, KeyModifierMask &mask) |
| 1141 | { |