MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / parseMultiSuppressComment

Method parseMultiSuppressComment

lib/suppressions.cpp:153–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151}
152
153std::vector<SuppressionList::Suppression> SuppressionList::parseMultiSuppressComment(const std::string &comment, std::string *errorMessage)
154{
155 std::vector<Suppression> suppressions;
156
157 // If this function is called we assume that comment starts with "cppcheck-suppress[".
158 const std::string::size_type start_position = comment.find('[');
159 const std::string::size_type end_position = comment.find(']', start_position);
160 if (end_position == std::string::npos) {
161 if (errorMessage && errorMessage->empty())
162 *errorMessage = "Bad multi suppression '" + comment + "'. legal format is cppcheck-suppress[errorId, errorId symbolName=arr, ...]";
163 return suppressions;
164 }
165
166 // parse all suppressions
167 for (std::string::size_type pos = start_position; pos < end_position;) {
168 const std::string::size_type pos1 = pos + 1;
169 pos = comment.find(',', pos1);
170 const std::string::size_type pos2 = (pos < end_position) ? pos : end_position;
171 if (pos1 == pos2)
172 continue;
173
174 Suppression s;
175 std::istringstream iss(comment.substr(pos1, pos2-pos1));
176
177 iss >> s.errorId;
178 if (!iss) {
179 if (errorMessage && errorMessage->empty())
180 *errorMessage = "Bad multi suppression '" + comment + "'. legal format is cppcheck-suppress[errorId, errorId symbolName=arr, ...]";
181 suppressions.clear();
182 return suppressions;
183 }
184
185 const std::string symbolNameString = "symbolName=";
186
187 while (iss) {
188 std::string word;
189 iss >> word;
190 if (!iss)
191 break;
192 if (word.find_first_not_of("+-*/%#;") == std::string::npos)
193 break;
194 if (startsWith(word, symbolNameString)) {
195 s.symbolName = word.substr(symbolNameString.size());
196 } else {
197 if (errorMessage && errorMessage->empty())
198 *errorMessage = "Bad multi suppression '" + comment + "'. legal format is cppcheck-suppress[errorId, errorId symbolName=arr, ...]";
199 suppressions.clear();
200 return suppressions;
201 }
202 }
203
204 suppressions.push_back(std::move(s));
205 }
206
207 return suppressions;
208}
209
210SuppressionList::Suppression SuppressionList::parseLine(std::string line)

Callers

nothing calls this directly

Calls 6

startsWithFunction · 0.70
findMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected