Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Improve backslash cases
Browse files Browse the repository at this point in the history
  • Loading branch information
natesdev committed May 12, 2024
1 parent e798147 commit 4cce140
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions shelly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,34 @@ string applyPlaceholders(const string &value)
++pos;
}

while ((pos = newValue.find("\\033")) != string::npos)
pos = 0;
while ((pos = newValue.find("\\n", pos)) != string::npos)
{
newValue.replace(pos, 4, "\033");
if (pos == 0 || (pos > 0 && newValue[pos - 1] != '\\')) {
newValue.replace(pos, 2, "\n");
}
++pos;
}

while ((pos = newValue.find("\\n")) != string::npos)
pos = 0;
while ((pos = newValue.find("\\033", pos)) != string::npos)
{
newValue.replace(pos, 3, "\n");
newValue.replace(pos, 4, "\033[");
pos += 2;
}

while((pos = newValue.find("\\")) != string::npos)
pos = 0;
while ((pos = newValue.find("\\{", pos)) != string::npos)
{
newValue.replace(pos, 1, "");
newValue.replace(pos, 2, "{");
++pos;
}

pos = 0;
while ((pos = newValue.find("\\\\", pos)) != string::npos)
{
newValue.replace(pos, 2, "\\");
++pos;
}

return newValue;
Expand Down

0 comments on commit 4cce140

Please sign in to comment.