Allow escaping strings in config

\n \\ and \t now will be translated to their escaped counterpart
This commit is contained in:
scorpion-26 2023-11-01 00:22:32 +01:00
parent 6e71e8a4f3
commit a2117475da
3 changed files with 22 additions and 0 deletions

View file

@ -6,6 +6,10 @@
# - Before the variable # - Before the variable
# - After the ':' # - After the ':'
# - After the value # - After the value
#
# String variables can be escaped ([Notation in config] -> "Result"):
# - foo\\bar -> "foo<backspace>bar"
# - foo\nbar -> "foo<newline>bar"
# The following three options control the ordering of the widgets. # The following three options control the ordering of the widgets.
# Reordering can cause slight margin inconsistencies, # Reordering can cause slight margin inconsistencies,

View file

@ -150,6 +150,18 @@ namespace Utils
} }
return ""; return "";
} }
inline void Replace(std::string& str, const std::string& string, const std::string& replacement)
{
size_t curPos = 0;
curPos = str.find(string);
while (curPos != std::string::npos)
{
str.replace(curPos, string.length(), replacement);
curPos += string.length();
curPos = str.find(string, curPos);
}
}
} }
struct Process struct Process

View file

@ -17,6 +17,12 @@ template<>
void ApplyProperty<std::string>(std::string& propertyToSet, const std::string_view& value) void ApplyProperty<std::string>(std::string& propertyToSet, const std::string_view& value)
{ {
propertyToSet = value; propertyToSet = value;
// Escape characters. This is a very hacky way to this, I know.
// TODO: Do something more efficient
Utils::Replace(propertyToSet, "\\n", "\n");
Utils::Replace(propertyToSet, "\\\\", "\\");
Utils::Replace(propertyToSet, "\\t", "\t");
} }
template<> template<>