| 1080 | } |
| 1081 | |
| 1082 | bool GameDatabase::TrackHash::parseHash(const std::string_view str) |
| 1083 | { |
| 1084 | constexpr u32 expected_length = SIZE * 2; |
| 1085 | if (str.length() != expected_length) |
| 1086 | return false; |
| 1087 | |
| 1088 | std::memset(data, 0, sizeof(data)); |
| 1089 | for (u32 i = 0; i < SIZE * 2; i++) |
| 1090 | { |
| 1091 | const char ch = str[i]; |
| 1092 | u8 b; |
| 1093 | if (ch >= '0' && ch <= '9') |
| 1094 | b = static_cast<u8>(ch - '0'); |
| 1095 | else if (ch >= 'a' && ch <= 'f') |
| 1096 | b = static_cast<u8>(ch - 'a') + 0xa; |
| 1097 | else if (ch >= 'A' && ch <= 'F') |
| 1098 | b = static_cast<u8>(ch - 'A') + 0xa; |
| 1099 | else |
| 1100 | return false; |
| 1101 | |
| 1102 | data[i / 2] |= ((i % 2) == 0) ? (b << 4) : b; |
| 1103 | } |
| 1104 | |
| 1105 | return true; |
| 1106 | } |
| 1107 | |
| 1108 | std::string GameDatabase::TrackHash::toString() const |
| 1109 | { |
no test coverage detected