Closed hvlad closed 2 weeks ago
Wouldn't be clearer to declare
prefix
asNoCaseString
and then use it'scompare
(in absence ofstarts_with
from C++20)?
compare()
takes into account string length and can not work as starts_with()
compare()
takes into account string length and can not work asstarts_with()
AFAIU this overload could work:
int compare(const_pointer s, const size_type n) const
Because c_str()
is guaranteed to be zero-terminated, result of prefix.compare(expanded_name.c_str(), prefix.length())
should do exactly the same what your code does if prefix
is NoCaseString
.
compare()
takes into account string length and can not work asstarts_with()
AFAIU this overload could work:
int compare(const_pointer s, const size_type n) const
Becausec_str()
is guaranteed to be zero-terminated, result ofprefix.compare(expanded_name.c_str(), prefix.length())
should do exactly the same what your code does ifprefix
isNoCaseString
.
It could access memory out of expanded_name
buffer, if expanded_name.length() < prefix.length()
If you offer to replace just one string (IgnoreCaseComparator::compare), I see no value in it at all as it definitely doesn't make code "clear" - it passes into compare()
one string with length of another one.
It could access memory out of
expanded_name
buffer, ifexpanded_name.length() < prefix.length()
Only if comparison is greedy and doesn't stop at the first different byte (which would be the expanded_name's terminating <NUL>
).
Wouldn't be clearer to declare
prefix
asNoCaseString
and then use it'scompare
(in absence ofstarts_with
from C++20)?