aboutsummaryrefslogtreecommitdiff
path: root/src/Process.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Process.cpp')
-rw-r--r--src/Process.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/Process.cpp b/src/Process.cpp
new file mode 100644
index 0000000..d82da42
--- /dev/null
+++ b/src/Process.cpp
@@ -0,0 +1,33 @@
+#include "../include/dchat/Process.hpp"
+
+namespace dchat
+{
+ std::string escapeCommand(const std::string &cmd)
+ {
+ std::string result;
+ result.reserve(cmd.size());
+ bool escape = false;
+
+ for(char c : cmd)
+ {
+ if(c == '\\')
+ escape = !escape;
+ else
+ {
+ if(escape)
+ result += "\\";
+
+ if(c == '"')
+ result += "\\\""; // \"
+ else if(c == '\'')
+ result += "\\'"; // \'
+ else
+ result += c;
+
+ escape = false;
+ }
+ }
+
+ return result;
+ }
+} \ No newline at end of file