| 136 | } |
| 137 | |
| 138 | std::string quote(const std::string& s) |
| 139 | { |
| 140 | bool spaces = s.find(' ') != std::string::npos; |
| 141 | if (!spaces && (s.find('\\') == std::string::npos) && |
| 142 | (s.find('\'') == std::string::npos) && |
| 143 | (s.find('"') == std::string::npos)) |
| 144 | return s; |
| 145 | |
| 146 | std::stringstream ss; |
| 147 | if (spaces) |
| 148 | ss << '"'; |
| 149 | |
| 150 | for (char c : s) |
| 151 | { |
| 152 | if ((c == '\\') || (c == '\"') || (c == '!')) |
| 153 | ss << '\\'; |
| 154 | ss << (char)c; |
| 155 | } |
| 156 | |
| 157 | if (spaces) |
| 158 | ss << '"'; |
| 159 | return ss.str(); |
| 160 | } |
| 161 | |
| 162 | std::string unhex(const std::string& s) |
| 163 | { |
no test coverage detected