string: add strcmp
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
8a6462a40c
commit
913cbc104a
@ -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
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user