Skip to content

Commit 65ce94e

Browse files
committed
Unify shall_quote under util/run
Removes the duplication of the shell_quote function (previously in both ansi-c/c_preprocess.cpp and util/run.cpp). Now only a single instance in util/run.cpp is used in both locations.
1 parent 4889328 commit 65ce94e

File tree

3 files changed

+4
-75
lines changed

3 files changed

+4
-75
lines changed

src/ansi-c/c_preprocess.cpp

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -18,80 +18,6 @@ Author: Daniel Kroening, [email protected]
1818

1919
#include <fstream>
2020

21-
/// quote a string for bash and CMD
22-
static std::string shell_quote(const std::string &src)
23-
{
24-
#ifdef _WIN32
25-
// first check if quoting is needed at all
26-
27-
if(src.find(' ')==std::string::npos &&
28-
src.find('"')==std::string::npos &&
29-
src.find('&')==std::string::npos &&
30-
src.find('|')==std::string::npos &&
31-
src.find('(')==std::string::npos &&
32-
src.find(')')==std::string::npos &&
33-
src.find('<')==std::string::npos &&
34-
src.find('>')==std::string::npos &&
35-
src.find('^')==std::string::npos)
36-
{
37-
// seems fine -- return as is
38-
return src;
39-
}
40-
41-
std::string result;
42-
43-
result+='"';
44-
45-
for(const char ch : src)
46-
{
47-
if(ch=='"')
48-
result+='"'; // quotes are doubled
49-
result+=ch;
50-
}
51-
52-
result+='"';
53-
54-
return result;
55-
56-
#else
57-
58-
// first check if quoting is needed at all
59-
60-
if(src.find(' ')==std::string::npos &&
61-
src.find('"')==std::string::npos &&
62-
src.find('*')==std::string::npos &&
63-
src.find('$')==std::string::npos &&
64-
src.find('\\')==std::string::npos &&
65-
src.find('?')==std::string::npos &&
66-
src.find('&')==std::string::npos &&
67-
src.find('|')==std::string::npos &&
68-
src.find('>')==std::string::npos &&
69-
src.find('<')==std::string::npos &&
70-
src.find('^')==std::string::npos &&
71-
src.find('\'')==std::string::npos)
72-
{
73-
// seems fine -- return as is
74-
return src;
75-
}
76-
77-
std::string result;
78-
79-
// the single quotes catch everything but themselves!
80-
result+='\'';
81-
82-
for(const char ch : src)
83-
{
84-
if(ch=='\'')
85-
result+="'\\''";
86-
result+=ch;
87-
}
88-
89-
result+='\'';
90-
91-
return result;
92-
#endif
93-
}
94-
9521
static void error_parse_line(
9622
const std::string &line,
9723
bool warning_only,

src/util/run.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ int run(
449449
}
450450

451451
/// quote a string for bash and CMD
452-
static std::string shell_quote(const std::string &src)
452+
std::string shell_quote(const std::string &src)
453453
{
454454
#ifdef _WIN32
455455
// first check if quoting is needed at all

src/util/run.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Date: August 2012
1616
#include <string>
1717
#include <vector>
1818

19+
/// This performs shell quoting if necessary on input \p src.
20+
std::string shell_quote(const std::string &src);
21+
1922
int run(const std::string &what, const std::vector<std::string> &argv);
2023

2124
/// This runs the executable given by the file name \p what.

0 commit comments

Comments
 (0)