diff options
author | 2021-02-03 17:44:17 -0500 | |
---|---|---|
committer | 2021-02-03 17:44:17 -0500 | |
commit | 0c57408ed81194046b56318dd6fd8583f8de44b3 (patch) | |
tree | 11bf099009e6a5c49ca1ff6fc18eb47322eb3c10 /src/emu/input.cpp | |
parent | c47ed0112e961c9ff0ee48e50e12cb3d4a2e3675 (diff) |
input.cpp, inputdev.cpp: Convert a few more functions to use std::string_view
Diffstat (limited to 'src/emu/input.cpp')
-rw-r--r-- | src/emu/input.cpp | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/src/emu/input.cpp b/src/emu/input.cpp index f767254fb7b..719cef8b45b 100644 --- a/src/emu/input.cpp +++ b/src/emu/input.cpp @@ -871,21 +871,21 @@ std::string input_manager::code_to_token(input_code code) const // token //------------------------------------------------- -input_code input_manager::code_from_token(const char *_token) +input_code input_manager::code_from_token(std::string_view _token) { // copy the token and break it into pieces std::string token[6]; - int numtokens; - for (numtokens = 0; numtokens < ARRAY_LENGTH(token); ) + int numtokens = 0; + while (numtokens < ARRAY_LENGTH(token)) { // make a token up to the next underscore - char *score = (char *)strchr(_token, '_'); - token[numtokens++].assign(_token, (score == nullptr) ? strlen(_token) : (score - _token)); + std::string_view::size_type score = _token.find('_'); + token[numtokens++].assign(_token, (std::string_view::npos == score) ? _token.length() : score); // if we hit the end, we're done, else advance our pointer - if (score == nullptr) + if (std::string_view::npos == score) break; - _token = score + 1; + _token.remove_prefix(score + 1); } // first token should be the devclass @@ -1228,53 +1228,52 @@ std::string input_manager::seq_to_tokens(const input_seq &seq) const // of a sequence //------------------------------------------------- -void input_manager::seq_from_tokens(input_seq &seq, const char *string) +void input_manager::seq_from_tokens(input_seq &seq, std::string_view string) { // start with a blank sequence seq.reset(); // loop until we're done - std::vector<char> strcopy(string, string + std::strlen(string) + 1); - char *str = &strcopy[0]; unsigned operators = 0; while (1) { // trim any leading spaces - while (*str != 0 && isspace(u8(*str))) - str++; + while (!string.empty() && isspace(u8(string[0]))) + string.remove_prefix(1); // bail if we're done - if (*str == 0) + if (string.empty()) return; // find the end of the token and make it upper-case along the way - char *strtemp; - for (strtemp = str; *strtemp != 0 && !isspace(u8(*strtemp)); strtemp++) - *strtemp = toupper(u8(*strtemp)); - char origspace = *strtemp; - *strtemp = 0; + std::string token; + while (!string.empty() && !isspace(u8(string[0]))) + { + token.push_back(toupper(u8(string[0]))); + string.remove_prefix(1); + } // look for common stuff input_code code; bool is_operator; - if (strcmp(str, "OR") == 0) + if (token == "OR") { code = input_seq::or_code; is_operator = true; } - else if (strcmp(str, "NOT") == 0) + else if (token == "NOT") { code = input_seq::not_code; is_operator = true; } - else if (strcmp(str, "DEFAULT") == 0) + else if (token == "DEFAULT") { code = input_seq::default_code; is_operator = false; } else { - code = code_from_token(str); + code = code_from_token(token); is_operator = false; } @@ -1288,7 +1287,7 @@ void input_manager::seq_from_tokens(input_seq &seq, const char *string) { if (code.device_class() < DEVICE_CLASS_FIRST_VALID) { - osd_printf_warning("Input: Dropping invalid input token %s\n", str); + osd_printf_warning("Input: Dropping invalid input token %s\n", token); while (operators) { seq.backspace(); @@ -1303,9 +1302,9 @@ void input_manager::seq_from_tokens(input_seq &seq, const char *string) } // advance - if (origspace == 0) + if (string.empty()) return; - str = strtemp + 1; + string.remove_prefix(1); } } @@ -1321,23 +1320,23 @@ bool input_manager::map_device_to_controller(const devicemap_table_type *devicem for (devicemap_table_type::const_iterator it = devicemap_table->begin(); it != devicemap_table->end(); it++) { - const char *deviceid = it->first.c_str(); - const char *controllername = it->second.c_str(); + std::string_view deviceid = it->first; + std::string_view controllername = it->second; // tokenize the controller name into device class and index (i.e. controller name should be of the form "GUNCODE_1") std::string token[2]; - int numtokens; - const char *_token = controllername; - for (numtokens = 0; numtokens < ARRAY_LENGTH(token); ) + int numtokens = 0; + std::string_view _token = controllername; + while (numtokens < ARRAY_LENGTH(token)) { // make a token up to the next underscore - char *score = (char *)strchr(_token, '_'); - token[numtokens++].assign(_token, (score == nullptr) ? strlen(_token) : (score - _token)); + std::string_view::size_type score = _token.find('_'); + token[numtokens++].assign(_token, (std::string_view::npos == score) ? _token.length() : score); // if we hit the end, we're done, else advance our pointer - if (score == nullptr) + if (std::string_view::npos == score) break; - _token = score + 1; + _token.remove_prefix(score + 1); } if (2 != numtokens) return false; |