* Parse a string representation of a keycode. * @param keystr Input. * @return A valid keycode or std::nullopt. */
| 117 | * @return A valid keycode or std::nullopt. |
| 118 | */ |
| 119 | static std::optional<uint16_t> ParseKeycode(std::string_view keystr) |
| 120 | { |
| 121 | if (keystr.empty()) return std::nullopt; |
| 122 | StringConsumer consumer{keystr}; |
| 123 | uint16_t keycode = 0; |
| 124 | while (consumer.AnyBytesLeft()) { |
| 125 | auto cur = consumer.ReadUntilChar('+', StringConsumer::SKIP_ONE_SEPARATOR); |
| 126 | auto code = ParseCode(cur); |
| 127 | if (!code.has_value()) return std::nullopt; |
| 128 | if (*code & WKC_SPECIAL_KEYS) { |
| 129 | /* Some completely wrong keycode we don't support. */ |
| 130 | if (*code & ~WKC_SPECIAL_KEYS) return std::nullopt; |
| 131 | keycode |= *code; |
| 132 | } else { |
| 133 | /* Ignore the code if it has more then 1 letter. */ |
| 134 | if (keycode & ~WKC_SPECIAL_KEYS) return std::nullopt; |
| 135 | keycode |= *code; |
| 136 | } |
| 137 | } |
| 138 | return keycode; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Parse a string to the keycodes it represents |
no test coverage detected