File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4242
4343#include " json.h"
4444
45+ std::string ImportProject::collectArgs (const std::string &cmd, std::vector<std::string> &args)
46+ {
47+ args.clear ();
48+
49+ std::string::size_type pos = 0 ;
50+ const std::string::size_type end = cmd.size ();
51+ std::string arg;
52+
53+ bool inDoubleQuotes = false ;
54+ bool inSingleQuotes = false ;
55+
56+ while (pos < end) {
57+ const char c = cmd[pos++];
58+
59+ if (c == ' ' ) {
60+ if (inDoubleQuotes || inSingleQuotes) {
61+ arg.push_back (c);
62+ continue ;
63+ }
64+
65+ if (!arg.empty ())
66+ args.push_back (arg);
67+ arg.clear ();
68+
69+ pos = cmd.find_first_not_of (' ' , pos);
70+
71+ continue ;
72+ }
73+
74+ if (c == ' \" ' && !inSingleQuotes) {
75+ inDoubleQuotes = !inDoubleQuotes;
76+ continue ;
77+ }
78+
79+ if (c == ' \' ' && !inDoubleQuotes) {
80+ inSingleQuotes = !inSingleQuotes;
81+ continue ;
82+ }
83+
84+ if (c == ' \\ ' && !inSingleQuotes) {
85+ if (pos == end) {
86+ arg.push_back (' \\ ' );
87+ break ;
88+ }
89+
90+ const char c = cmd[pos++];
91+
92+ if (!std::strchr (" \\\"\' " , c))
93+ arg.push_back (' \\ ' );
94+
95+ arg.push_back (c);
96+ continue ;
97+ }
98+
99+ arg.push_back (c);
100+ }
101+
102+ if (inSingleQuotes || inDoubleQuotes)
103+ return " Missing closing quote in command string" ;
104+
105+ if (!arg.empty ())
106+ args.push_back (arg);
107+
108+ return " " ;
109+ }
110+
45111void ImportProject::ignorePaths (const std::vector<std::string> &ipaths, bool debug)
46112{
47113 PathMatch matcher (ipaths, Path::getCurrentPath ());
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {
103103protected:
104104 bool importCompileCommands (std::istream &istr);
105105 bool importCppcheckGuiProject (std::istream &istr, Settings &settings, Suppressions &supprs);
106+ static std::string collectArgs (const std::string &cmd, std::vector<std::string> &args);
106107
107108private:
108109 struct SharedItemsProject {
You can’t perform that action at this time.
0 commit comments