MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ParseCode

Function ParseCode

src/hotkeys.cpp:97–112  ·  view source on GitHub ↗

* Try to parse a single part of a keycode. * @param keystr Input. * @return A keycode if a match is found. */

Source from the content-addressed store, hash-verified

95 * @return A keycode if a match is found.
96 */
97static 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.

Callers 1

ParseKeycodeFunction · 0.85

Calls 3

StrTrimViewFunction · 0.85
StrEqualsIgnoreCaseFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected