* Quote an argument for shell. * * @note This is intended for help, not for security-sensitive purposes. */
| 137 | * @note This is intended for help, not for security-sensitive purposes. |
| 138 | */ |
| 139 | std::string ShellQuote(const std::string& s) |
| 140 | { |
| 141 | std::string result; |
| 142 | result.reserve(s.size() * 2); |
| 143 | for (const char ch: s) { |
| 144 | if (ch == '\'') { |
| 145 | result += "'\''"; |
| 146 | } else { |
| 147 | result += ch; |
| 148 | } |
| 149 | } |
| 150 | return "'" + result + "'"; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Shell-quotes the argument if it needs quoting, else returns it literally, to save typing. |
no test coverage detected