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+ 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+ char c = cmd[pos];
58+
59+ if (c == ' ' ) {
60+ if (inDoubleQuotes || inSingleQuotes) {
61+ arg.push_back (c);
62+ pos++;
63+ continue ;
64+ }
65+
66+ if (!arg.empty ())
67+ args.push_back (arg);
68+ arg.clear ();
69+
70+ while (c == ' ' ) {
71+ pos++;
72+ if (pos == end)
73+ break ;
74+ c = cmd[pos];
75+ }
76+
77+ continue ;
78+ }
79+
80+ if (c == ' \" ' && !inSingleQuotes) {
81+ inDoubleQuotes = !inDoubleQuotes;
82+ pos++;
83+ continue ;
84+ }
85+
86+ if (c == ' \' ' ) {
87+ inSingleQuotes = !inSingleQuotes;
88+ pos++;
89+ continue ;
90+ }
91+
92+ if (c == ' \\ ' && !inSingleQuotes) {
93+ pos++;
94+
95+ if (pos == end) {
96+ arg.push_back (' \\ ' );
97+ break ;
98+ }
99+
100+ c = cmd[pos];
101+
102+ if (!std::strchr (" \\\"\' " , c))
103+ arg.push_back (' \\ ' );
104+
105+ arg.push_back (c);
106+ pos++;
107+ continue ;
108+ }
109+
110+ arg.push_back (c);
111+ pos++;
112+ }
113+
114+ if (inSingleQuotes || inDoubleQuotes)
115+ return " Missing closing quote in command string" ;
116+
117+ if (!arg.empty ())
118+ args.push_back (arg);
119+
120+ return " " ;
121+ }
122+
45123void ImportProject::ignorePaths (const std::vector<std::string> &ipaths, bool debug)
46124{
47125 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