Skip to content

Commit 699f7b0

Browse files
authored
Applied some cppcheck [useStlAlgorithm] recommendations. (#1924)
* Use copy_if instead of raw loop. * Replaced for loop with std::any_of.
1 parent 6ba7691 commit 699f7b0

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

Packet++/src/Asn1Codec.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,9 @@ namespace pcpp
612612
throw std::invalid_argument("Value is not a valid hex stream");
613613
}
614614

615-
for (const char i : valueStr)
615+
if (std::any_of(valueStr.begin(), valueStr.end(), [](char c) { return !std::isxdigit(c); }))
616616
{
617-
if (!std::isxdigit(i))
618-
{
619-
throw std::invalid_argument("Value is not a valid hex stream");
620-
}
617+
throw std::invalid_argument("Value is not a valid hex stream");
621618
}
622619

623620
return valueStr;

Packet++/src/SmtpLayer.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,8 @@ namespace pcpp
4444
}
4545

4646
std::string optionWithEscapeChars;
47-
for (char ch : option)
48-
{
49-
if (ch < 127 && ch > 31)
50-
{
51-
optionWithEscapeChars.push_back(ch);
52-
}
53-
}
47+
std::copy_if(option.begin(), option.end(), std::back_inserter(optionWithEscapeChars),
48+
[](char ch) { return ch < 127 && ch > 31; });
5449

5550
return optionWithEscapeChars;
5651
}

0 commit comments

Comments
 (0)