Codechange: Use range-for to iterate keycode-to-name lookups. (#12429)

Replaces C-style looping.
This commit is contained in:
Peter Nelson 2024-04-06 19:30:01 +01:00 committed by GitHub
parent b905209421
commit a4c2f0778a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 8 deletions

View File

@ -26,12 +26,12 @@ static std::vector<HotkeyList*> *_hotkey_lists = nullptr;
/** String representation of a keycode */
struct KeycodeNames {
const char *name; ///< Name of the keycode
const std::string_view name; ///< Name of the keycode
WindowKeyCodes keycode; ///< The keycode
};
/** Array of non-standard keycodes that can be used in the hotkeys config file. */
static const KeycodeNames _keycode_to_name[] = {
static const std::initializer_list<KeycodeNames> _keycode_to_name = {
{"SHIFT", WKC_SHIFT},
{"CTRL", WKC_CTRL},
{"ALT", WKC_ALT},
@ -100,9 +100,9 @@ static uint16_t ParseCode(const char *start, const char *end)
while (start < end && *start == ' ') start++;
while (end > start && *end == ' ') end--;
std::string_view str{start, (size_t)(end - start)};
for (uint i = 0; i < lengthof(_keycode_to_name); i++) {
if (StrEqualsIgnoreCase(str, _keycode_to_name[i].name)) {
return _keycode_to_name[i].keycode;
for (const auto &kn : _keycode_to_name) {
if (StrEqualsIgnoreCase(str, kn.name)) {
return kn.keycode;
}
}
if (end - start == 1) {
@ -193,9 +193,9 @@ static std::string KeycodeToString(uint16_t keycode)
if (!str.empty()) str += "+";
keycode = keycode & ~WKC_SPECIAL_KEYS;
for (uint i = 0; i < lengthof(_keycode_to_name); i++) {
if (_keycode_to_name[i].keycode == keycode) {
str += _keycode_to_name[i].name;
for (const auto &kn : _keycode_to_name) {
if (kn.keycode == keycode) {
str += kn.name;
return str;
}
}