mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 03:02:49 +00:00
Allow escaping strings in config
\n \\ and \t now will be translated to their escaped counterpart
This commit is contained in:
parent
6e71e8a4f3
commit
a2117475da
3 changed files with 22 additions and 0 deletions
|
@ -6,6 +6,10 @@
|
|||
# - Before the variable
|
||||
# - After the ':'
|
||||
# - 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.
|
||||
# Reordering can cause slight margin inconsistencies,
|
||||
|
|
12
src/Common.h
12
src/Common.h
|
@ -150,6 +150,18 @@ namespace Utils
|
|||
}
|
||||
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
|
||||
|
|
|
@ -17,6 +17,12 @@ template<>
|
|||
void ApplyProperty<std::string>(std::string& propertyToSet, const std::string_view& 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<>
|
||||
|
|
Loading…
Reference in a new issue