| 40 | } |
| 41 | |
| 42 | void JoystickGuid::fromString(StringView string) |
| 43 | { |
| 44 | if (string.empty()) { |
| 45 | fromType(JoystickGuidType::Unknown); |
| 46 | } else if (string == "default"_s) { |
| 47 | fromType(JoystickGuidType::Default); |
| 48 | } else if (string == "hidapi"_s) { |
| 49 | fromType(JoystickGuidType::Hidapi); |
| 50 | } else if (string == "xinput"_s) { |
| 51 | fromType(JoystickGuidType::Xinput); |
| 52 | } else { |
| 53 | if (string.size() != sizeof(data) * 2) { |
| 54 | fromType(JoystickGuidType::Unknown); |
| 55 | } else { |
| 56 | char component[3]; |
| 57 | component[2] = '\0'; |
| 58 | for (uint32_t i = 0, j = 0; i < sizeof(data); i++) { |
| 59 | component[0] = string[j++]; |
| 60 | component[1] = string[j++]; |
| 61 | data[i] = (std::uint8_t)std::strtoul(component, nullptr, 16); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | bool JoystickGuid::isValid() const |
| 68 | { |
no test coverage detected