mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 05:40:01 -06:00
Common/SettingsHandler: Use std::string_view where applicable
Allows passed in strings to be non-allocating.
This commit is contained in:
@ -38,27 +38,27 @@ void SettingsHandler::SetBytes(Buffer&& buffer)
|
||||
Decrypt();
|
||||
}
|
||||
|
||||
std::string SettingsHandler::GetValue(const std::string& key) const
|
||||
std::string SettingsHandler::GetValue(std::string_view key) const
|
||||
{
|
||||
std::string delim = std::string("\r\n");
|
||||
std::string toFind = delim + key + "=";
|
||||
constexpr char delim[] = "\r\n";
|
||||
std::string toFind = std::string(delim).append(key).append("=");
|
||||
size_t found = decoded.find(toFind);
|
||||
|
||||
if (found != decoded.npos)
|
||||
if (found != std::string_view::npos)
|
||||
{
|
||||
size_t delimFound = decoded.find(delim, found + toFind.length());
|
||||
if (delimFound == decoded.npos)
|
||||
if (delimFound == std::string_view::npos)
|
||||
delimFound = decoded.length() - 1;
|
||||
return decoded.substr(found + toFind.length(), delimFound - (found + toFind.length()));
|
||||
}
|
||||
else
|
||||
{
|
||||
toFind = key + "=";
|
||||
toFind = std::string(key).append("=");
|
||||
found = decoded.find(toFind);
|
||||
if (found == 0)
|
||||
{
|
||||
size_t delimFound = decoded.find(delim, found + toFind.length());
|
||||
if (delimFound == decoded.npos)
|
||||
if (delimFound == std::string_view::npos)
|
||||
delimFound = decoded.length() - 1;
|
||||
return decoded.substr(found + toFind.length(), delimFound - (found + toFind.length()));
|
||||
}
|
||||
@ -89,7 +89,7 @@ void SettingsHandler::Reset()
|
||||
m_buffer = {};
|
||||
}
|
||||
|
||||
void SettingsHandler::AddSetting(const std::string& key, const std::string& value)
|
||||
void SettingsHandler::AddSetting(std::string_view key, std::string_view value)
|
||||
{
|
||||
for (const char& c : key)
|
||||
{
|
||||
|
Reference in New Issue
Block a user