Skip to content

Commit fdc3536

Browse files
committed
handle ; and // inside extra comment
1 parent e8d8cc7 commit fdc3536

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

lib/suppressions.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ std::string SuppressionList::parseXmlFile(const char *filename)
153153
return "";
154154
}
155155

156+
static std::string::size_type findExtraCommentStart(const std::string &comment, std::string::size_type startPos)
157+
{
158+
const std::string::size_type semiPos = comment.find(';', startPos);
159+
const std::string::size_type slashPos = comment.find("//", startPos);
160+
161+
if (semiPos != std::string::npos && semiPos < slashPos)
162+
return semiPos + 1;
163+
164+
if (slashPos != std::string::npos)
165+
return slashPos + 2;
166+
167+
return std::string::npos;
168+
}
169+
156170
std::vector<SuppressionList::Suppression> SuppressionList::parseMultiSuppressComment(const std::string &comment, std::string *errorMessage)
157171
{
158172
std::vector<Suppression> suppressions;
@@ -207,18 +221,12 @@ std::vector<SuppressionList::Suppression> SuppressionList::parseMultiSuppressCom
207221
suppressions.push_back(std::move(s));
208222
}
209223

210-
std::string::size_type extraPos = comment.find(';', end_position);
211-
std::size_t delimSize = 1;
212-
213-
if (extraPos == std::string::npos) {
214-
extraPos = comment.find("//", end_position);
215-
delimSize = 2;
216-
}
224+
const std::string::size_type extraPos = findExtraCommentStart(comment, end_position);
217225

218226
if (extraPos == std::string::npos)
219227
return suppressions;
220228

221-
std::string extraComment = comment.substr(extraPos + delimSize);
229+
std::string extraComment = comment.substr(extraPos);
222230

223231
if (extraComment.size() >= 2 && extraComment.compare(extraComment.size() - 2, 2, "*/") == 0)
224232
extraComment.erase(extraComment.size() - 2, 2);
@@ -384,16 +392,10 @@ bool SuppressionList::Suppression::parseComment(std::string comment, std::string
384392
if (comment.compare(comment.size() - 2, 2, "*/") == 0)
385393
comment.erase(comment.size() - 2, 2);
386394

387-
std::string::size_type extraPos = comment.find(';');
388-
std::string::size_type extraDelimiterSize = 1;
389-
390-
if (extraPos == std::string::npos) {
391-
extraPos = comment.find("//", 2);
392-
extraDelimiterSize = 2;
393-
}
395+
const std::string::size_type extraPos = findExtraCommentStart(comment, 2);
394396

395397
if (extraPos != std::string::npos) {
396-
extraComment = trim(comment.substr(extraPos + extraDelimiterSize));
398+
extraComment = trim(comment.substr(extraPos));
397399
for (auto it = extraComment.begin(); it != extraComment.end();)
398400
it = *it & 0x80 ? extraComment.erase(it) : it + 1;
399401
comment.erase(extraPos);

0 commit comments

Comments
 (0)