From f7cc3a9e735e4925018d64bc5a155a17004c6cc9 Mon Sep 17 00:00:00 2001 From: Lirusaito Date: Thu, 4 Apr 2019 21:50:39 -0400 Subject: [PATCH] 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. --- indra/newview/llpreviewscript.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index 03f6f94b6..cb8d312f1 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -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);