InputCommon: fix serialization of control expression with line breaks

The control expression editor allows line breaks, but the serialization was
losing anything after the first line break (/r /n).
Instead of opting to encode them and decode them on serialization
(which I tried but was not safe, as it would lose /n written in the string by users),
I opted to replace them with a space.
This commit is contained in:
Filoppi
2021-05-11 16:30:29 +03:00
parent eb5cd9be78
commit 574477866f
4 changed files with 25 additions and 4 deletions

View File

@ -219,7 +219,7 @@ std::string ArrayToString(const u8* data, u32 size, int line_len, bool spaces)
return oss.str();
}
// Turns " hello " into "hello". Also handles tabs.
// Turns "\n\r\t hello " into "hello" (trims at the start and end but not inside).
std::string_view StripSpaces(std::string_view str)
{
const size_t s = str.find_first_not_of(" \t\r\n");
@ -241,6 +241,13 @@ std::string_view StripQuotes(std::string_view s)
return s;
}
// Turns "\n\rhello" into " hello".
void ReplaceBreaksWithSpaces(std::string& str)
{
std::replace(str.begin(), str.end(), '\r', ' ');
std::replace(str.begin(), str.end(), '\n', ' ');
}
bool TryParse(const std::string& str, bool* const output)
{
float value;