* Try to parse a single part of a keycode. * @param keystr Input. * @return A keycode if a match is found. */
| 95 | * @return A keycode if a match is found. |
| 96 | */ |
| 97 | static std::optional<uint16_t> ParseCode(std::string_view keystr) |
| 98 | { |
| 99 | keystr = StrTrimView(keystr, StringConsumer::WHITESPACE_NO_NEWLINE); |
| 100 | for (const auto &kn : _keycode_to_name) { |
| 101 | if (StrEqualsIgnoreCase(keystr, kn.name)) { |
| 102 | return kn.keycode; |
| 103 | } |
| 104 | } |
| 105 | if (keystr.size() == 1) { |
| 106 | auto c = keystr[0]; |
| 107 | if (c >= 'a' && c <= 'z') return c - ('a'-'A'); |
| 108 | /* Ignore invalid keycodes */ |
| 109 | if (static_cast<uint8_t>(c) < 128) return c; |
| 110 | } |
| 111 | return std::nullopt; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Parse a string representation of a keycode. |
no test coverage detected