string: add strcmp

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2023-10-10 16:39:19 +02:00
parent 8a6462a40c
commit 913cbc104a

View File

@ -356,6 +356,26 @@ namespace stdex
return z;
}
///
/// Binary compare two strings
///
/// \param[in] str1 String 1
/// \param[in] str2 String 2
///
/// \return Negative if str1<str2; positive if str1>str2; zero if str1==str2
///
template <class T1, class T2>
inline int strcmp(const T1* str1, const T2* str2)
{
_Assume_(str1 && str2);
T1 a; T2 b;
for (size_t i = 0; (a = str1[i]) | (b = str2[i]); ++i) {
if (a > b) return +1;
if (a < b) return -1;
}
return 0;
}
///
/// Binary compare two strings
///