mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Use range-for to iterate keycode-to-name lookups. (#12429)
Replaces C-style looping.
This commit is contained in:
parent
b905209421
commit
a4c2f0778a
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue