aboutsummaryrefslogtreecommitdiff
path: root/src/Process.cpp
blob: d82da425cfb7ad41dd9122dc3e9d8c2b0c6cbfd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
    }
}