bool input_manager::map_device_to_controller(const devicemap_table_type *devicemap_table) { if (nullptr == devicemap_table) return true; 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(); // 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); ) { // make a token up to the next underscore char *score = (char *)strchr(_token, '_'); token[numtokens++].assign(_token, (score == nullptr) ? strlen(_token) : (score - _token)); // if we hit the end, we're done, else advance our pointer if (score == nullptr) break; _token = score + 1; } if (2 != numtokens) return false; // first token should be the devclass input_device_class devclass = input_device_class((*devclass_token_table)[strmakeupper(token[0]).c_str()]); if (devclass == ~input_device_class(0)) return false; // second token should be the devindex int devindex = 0; if (1 != sscanf(token[1].c_str(), "%d", &devindex)) return false; devindex--; if (devindex >= DEVICE_INDEX_MAXIMUM) return false; // enumerate through devices and look for a match input_class *input_devclass = m_class[devclass].get(); for (int devnum = 0; devnum <= input_devclass->maxindex(); devnum++) { input_device *device = input_devclass->device(devnum); if (device != nullptr && device->match_device_id(deviceid)) { // remap devindex input_devclass->remap_device_index(device->devindex(), devindex); osd_printf_verbose("Input: Remapped %s #%d: %s (device id: %s)\n", input_devclass->name(), devindex, device->name(), device->id()); break; } } } return true; }
TEST(corestr,strmakeupper) { std::string value = "test"; EXPECT_STREQ("TEST", strmakeupper(value).c_str()); }
#include "catch.hpp" #include "corestr.h" TEST_CASE("String make upper", "[util]") { std::string value = "test"; REQUIRE(strmakeupper(value) == "TEST"); } TEST_CASE("String make lower", "[util]") { std::string value = "ValUE"; REQUIRE(strmakelower(value) == "value"); } TEST_CASE("String replace", "[util]") { std::string value = "Main string"; REQUIRE(strreplace(value,"str","aaa") == 1); REQUIRE(value == "Main aaaing"); REQUIRE(strreplace(value,"a","b") == 4); } TEST_CASE("String replace counting", "[util]") { std::string value = "Main aaaing"; REQUIRE(strreplace(value,"a","b") == 4); } TEST_CASE("String trimming spaces", "[util]")