FirebirdSQL / firebird

Firebird server, client and tools
https://www.firebirdsql.org/
1.19k stars 204 forks source link

Implement #8066 : Make protocol schemes case-insensitive. #8097

Closed hvlad closed 2 weeks ago

aafemt commented 2 weeks ago

Wouldn't be clearer to declare prefix as NoCaseString and then use it's compare (in absence of starts_with from C++20)?

hvlad commented 2 weeks ago

Wouldn't be clearer to declare prefix as NoCaseString and then use it's compare (in absence of starts_with from C++20)?

compare() takes into account string length and can not work as starts_with()

aafemt commented 2 weeks ago

compare() takes into account string length and can not work as starts_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.

hvlad commented 2 weeks ago

compare() takes into account string length and can not work as starts_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.

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.

aafemt commented 2 weeks ago

It could access memory out of expanded_name buffer, if expanded_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>).