From cd006dd3df49af7e6c93ec6a73ff2beef8f26fcd Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Mon, 28 Sep 2026 19:32:27 +0200 Subject: [PATCH] RMG-Input: refactor Sdl3GuidWithIndex.cpp --- .../RMG-Input/Utilities/Sdl3GuidWithIndex.cpp | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Source/RMG-Input/Utilities/Sdl3GuidWithIndex.cpp b/Source/RMG-Input/Utilities/Sdl3GuidWithIndex.cpp index 1d965e75..c111cbca 100644 --- a/Source/RMG-Input/Utilities/Sdl3GuidWithIndex.cpp +++ b/Source/RMG-Input/Utilities/Sdl3GuidWithIndex.cpp @@ -8,24 +8,31 @@ * along with this program. If not, see . */ #include "Sdl3GuidWithIndex.hpp" + #include #include + #include using namespace Utilities; std::string Utilities::Sdl3GuidWithIndex(std::vector& guidsWithoutIndex, SDL_JoystickID joystickId) { - char guidBuffer[33]{}; - SDL_GUIDToString(SDL_GetJoystickGUIDForID(joystickId), guidBuffer, sizeof(guidBuffer)); - std::string guidWithoutIndex = std::string(guidBuffer); - + char guidBuffer[33] = {0}; int guidIndex = 0; - for(auto& otherDeviceGuidWithoutIndex : guidsWithoutIndex) { - if(otherDeviceGuidWithoutIndex == guidWithoutIndex) guidIndex++; + std::string guidWithoutIndex; + + SDL_GUIDToString(SDL_GetJoystickGUIDForID(joystickId), guidBuffer, sizeof(guidBuffer)); + guidWithoutIndex = guidBuffer; + + for (const auto& otherDeviceGuidWithoutIndex : guidsWithoutIndex) + { + if (otherDeviceGuidWithoutIndex == guidWithoutIndex) + { + guidIndex++; + } } guidsWithoutIndex.push_back(guidWithoutIndex); - std::string guidWithIndex = guidWithoutIndex + "/" + std::to_string(guidIndex); - return guidWithIndex; + return guidWithoutIndex + "/" + std::to_string(guidIndex); }