fix: explicitly copy-convert to std::string in StartsWith/EndsWith matchers

Instead of relying on automatic conversions, which won't happen if
they're explicit!
This commit is contained in:
Giel van Schijndel 2023-10-12 16:24:06 +02:00
parent a6d7fa8c0c
commit c618dd98d0

View file

@ -1048,7 +1048,7 @@ class StartsWithMatcher {
template <typename MatcheeStringType>
bool MatchAndExplain(const MatcheeStringType& s,
MatchResultListener* /* listener */) const {
const StringType& s2(s);
const StringType s2(s);
return s2.length() >= prefix_.length() &&
s2.substr(0, prefix_.length()) == prefix_;
}
@ -1102,7 +1102,7 @@ class EndsWithMatcher {
template <typename MatcheeStringType>
bool MatchAndExplain(const MatcheeStringType& s,
MatchResultListener* /* listener */) const {
const StringType& s2(s);
const StringType s2(s);
return s2.length() >= suffix_.length() &&
s2.substr(s2.length() - suffix_.length()) == suffix_;
}