diff --git a/Source/Core/Core/GeckoCodeConfig.cpp b/Source/Core/Core/GeckoCodeConfig.cpp index f50b848d68..8cae3d8b68 100644 --- a/Source/Core/Core/GeckoCodeConfig.cpp +++ b/Source/Core/Core/GeckoCodeConfig.cpp @@ -79,14 +79,15 @@ std::vector LoadCodes(const IniFile& globalIni, const IniFile& localI for (const std::string& line : lines) { - if (line.size() == 0 || line[0] != '$') + if (line.empty() || line[0] != '$') { continue; } - std::string name = line.substr(1); + for (GeckoCode& ogcode : gcodes) { - if (ogcode.name == name) + // Exclude the initial '$' from the comparison. + if (line.compare(1, std::string::npos, ogcode.name) == 0) { ogcode.enabled = true; } @@ -97,44 +98,39 @@ std::vector LoadCodes(const IniFile& globalIni, const IniFile& localI return gcodes; } +static std::string MakeGeckoCodeTitle(const GeckoCode& code) +{ + std::string title = '$' + code.name; + + if (!code.creator.empty()) + { + title += " [" + code.creator + ']'; + } + + return title; +} + // used by the SaveGeckoCodes function static void SaveGeckoCode(std::vector& lines, std::vector& enabledLines, const GeckoCode& gcode) { if (gcode.enabled) - enabledLines.push_back("$" + gcode.name); + enabledLines.push_back('$' + gcode.name); if (!gcode.user_defined) return; - std::string name; - - // save the name - name += '$'; - name += gcode.name; - - // save the creator name - if (gcode.creator.size()) - { - name += " ["; - name += gcode.creator; - name += ']'; - } - - lines.push_back(name); + lines.push_back(MakeGeckoCodeTitle(gcode)); // save all the code lines for (const GeckoCode::Code& code : gcode.codes) { - // ss << std::hex << codes_iter->address << ' ' << codes_iter->data; - // lines.push_back(StringFromFormat("%08X %08X", codes_iter->address, codes_iter->data)); lines.push_back(code.original_line); - // ss.clear(); } // save the notes for (const std::string& note : gcode.notes) - lines.push_back(std::string("*") + note); + lines.push_back('*' + note); } void SaveCodes(IniFile& inifile, const std::vector& gcodes)