MCPcopy Create free account
hub / github.com/catchorg/Catch2 / escape_arg

Function escape_arg

tools/misc/coverage-helper.cpp:12–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include <vector>
11
12std::string escape_arg(const std::string& arg) {
13 if (arg.empty() == false &&
14 arg.find_first_of(" \t\n\v\"") == arg.npos) {
15 return arg;
16 }
17
18 std::string escaped;
19 escaped.push_back('"');
20 for (auto it = arg.begin(); ; ++it) {
21 int num_backslashes = 0;
22
23 while (it != arg.end() && *it == '\\') {
24 ++it;
25 ++num_backslashes;
26 }
27
28 if (it == arg.end()) {
29 escaped.append(num_backslashes * 2, '\\');
30 break;
31 } else if (*it == '"') {
32 escaped.append((num_backslashes + 1) * 2, '\\');
33 escaped.push_back('"');
34 escaped.push_back(*it);
35 } else {
36 escaped.append(num_backslashes, '\\');
37 escaped.push_back(*it);
38 }
39 }
40 escaped.push_back('"');
41
42 return escaped;
43}
44
45
46void create_empty_file(std::string const& path) {

Callers 2

exec_cmdFunction · 0.85
mainFunction · 0.85

Calls 3

emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected