Feature Request: Trim spaces off of end of script lines

In order to preserve your ability to edit, this only happens to the asset
we send to the server, you will not notice until you reopen the script.
This is done as optimally as possible, upon each save.
This feature takes into account the possibility that spaces may
be following a quote and therefore it does not trim spaces in these cases.
It is also aware that you may use escaped quotes inside a string, and that
that does not mark the end of a string and therefore whitespace
is not stripped then.
This commit is contained in:
Lirusaito
2019-04-04 21:50:39 -04:00
parent 7d56d772d4
commit f7cc3a9e73

View File

@@ -481,9 +481,33 @@ bool LLScriptEdCore::writeToFile(const std::string& filename)
std::string utf8text = mEditor->getText();
// Special case for a completely empty script - stuff in one space so it can store properly. See SL-46889
if (utf8text.size() == 0)
if (utf8text.empty())
{
utf8text = " ";
utf8text.push_back(' ');
}
else // We cut the fat ones down to size
{
std::stringstream strm(utf8text);
utf8text.clear();
bool quote = false;
for (std::string line; std::getline(strm, line);)
{
//if ((std::count(line.begin(), line.end(), '"') % 2) == 0) quote = !quote; // This would work if escaping wasn't a thing
bool backslash = false;
for (const auto& ch : line)
{
switch (ch)
{
case '\\': backslash = !backslash; break;
case '"': if (!backslash) quote = !quote; // Fall through
default: backslash = false; break;
}
}
if (quote) LLStringUtil::trimTail(line);
if (!utf8text.empty()) utf8text += '\n';
utf8text += line;
}
if (utf8text.empty()) utf8text.push_back(' ');
}
fputs(utf8text.c_str(), fp);