revised qse_mbsxcmp(), qse_wcsxcmp(), qse_mbsxcasecmp(), qse_wcsxcasecmp()

This commit is contained in:
hyung-hwan 2017-12-31 16:40:24 +00:00
parent f595c300c1
commit 5174784cfe

View File

@ -42,9 +42,15 @@ int qse_mbsxcmp (const qse_mchar_t* s1, qse_size_t ln, const qse_mchar_t* s2)
{ {
const qse_mchar_t* end = s1 + ln; const qse_mchar_t* end = s1 + ln;
while (s1 < end && *s2 != QSE_MT('\0') && *s1 == *s2) s1++, s2++; while (s1 < end && *s2 != QSE_MT('\0') && *s1 == *s2) s1++, s2++;
if (s1 == end && *s2 == QSE_MT('\0')) return 0;
if (*s1 == *s2) return (s1 < end)? 1: -1; if (s1 == end)
return (*s1 > *s2)? 1: -1; {
return (*s2 == QSE_MT('\0'))? 0: -1;
}
else /* str1 < end */
{
return (*s1 >= *s2)? 1: -1;
}
} }
int qse_mbsxncmp ( int qse_mbsxncmp (
@ -84,6 +90,7 @@ int qse_mbscasecmp (const qse_mchar_t* s1, const qse_mchar_t* s2)
int qse_mbsxcasecmp (const qse_mchar_t* s1, qse_size_t ln, const qse_mchar_t* s2) int qse_mbsxcasecmp (const qse_mchar_t* s1, qse_size_t ln, const qse_mchar_t* s2)
{ {
#if 0
qse_mchar_t c1, c2; qse_mchar_t c1, c2;
const qse_mchar_t* end = s1 + ln; const qse_mchar_t* end = s1 + ln;
@ -96,6 +103,27 @@ int qse_mbsxcasecmp (const qse_mchar_t* s1, qse_size_t ln, const qse_mchar_t* s2
if (s1 == end && c2 == QSE_MT('\0')) return 0; if (s1 == end && c2 == QSE_MT('\0')) return 0;
if (c1 == c2) return (s1 < end)? 1: -1; if (c1 == c2) return (s1 < end)? 1: -1;
return (c1 > c2)? 1: -1; return (c1 > c2)? 1: -1;
#else
qse_mchar_t c1, c2;
const qse_mchar_t* end = s1 + ln;
while (s1 < end && *s2 != QSE_MT('\0'))
{
c1 = QSE_TOMUPPER(*s1);
c2 = QSE_TOMUPPER(*s2);
if (c1 != c2) break;
s1++; s2++;
}
if (s1 == end)
{
return (*s2 == QSE_MT('\0'))? 0: -1;
}
else
{
return (c1 >= c2)? 1: -1;
}
#endif
} }
int qse_mbsxncasecmp ( int qse_mbsxncasecmp (
@ -166,9 +194,14 @@ int qse_wcsxcmp (const qse_wchar_t* s1, qse_size_t ln, const qse_wchar_t* s2)
{ {
const qse_wchar_t* end = s1 + ln; const qse_wchar_t* end = s1 + ln;
while (s1 < end && *s2 != QSE_WT('\0') && *s1 == *s2) s1++, s2++; while (s1 < end && *s2 != QSE_WT('\0') && *s1 == *s2) s1++, s2++;
if (s1 == end && *s2 == QSE_WT('\0')) return 0; if (s1 == end)
if (*s1 == *s2) return (s1 < end)? 1: -1; {
return (*s1 > *s2)? 1: -1; return (*s2 == QSE_WT('\0'))? 0: -1;
}
else /* str1 < end */
{
return (*s1 >= *s2)? 1: -1;
}
} }
int qse_wcsxncmp ( int qse_wcsxncmp (
@ -208,6 +241,7 @@ int qse_wcscasecmp (const qse_wchar_t* s1, const qse_wchar_t* s2)
int qse_wcsxcasecmp (const qse_wchar_t* s1, qse_size_t ln, const qse_wchar_t* s2) int qse_wcsxcasecmp (const qse_wchar_t* s1, qse_size_t ln, const qse_wchar_t* s2)
{ {
#if 0
qse_wchar_t c1, c2; qse_wchar_t c1, c2;
const qse_wchar_t* end = s1 + ln; const qse_wchar_t* end = s1 + ln;
@ -220,6 +254,27 @@ int qse_wcsxcasecmp (const qse_wchar_t* s1, qse_size_t ln, const qse_wchar_t* s2
if (s1 == end && c2 == QSE_WT('\0')) return 0; if (s1 == end && c2 == QSE_WT('\0')) return 0;
if (c1 == c2) return (s1 < end)? 1: -1; if (c1 == c2) return (s1 < end)? 1: -1;
return (c1 > c2)? 1: -1; return (c1 > c2)? 1: -1;
#else
qse_wchar_t c1, c2;
const qse_wchar_t* end = s1 + ln;
while (s1 < end && *s2 != QSE_WT('\0'))
{
c1 = QSE_TOWUPPER(*s1);
c2 = QSE_TOWUPPER(*s2);
if (c1 != c2) break;
s1++; s2++;
}
if (s1 == end)
{
return (*s2 == QSE_WT('\0'))? 0: -1;
}
else
{
return (c1 >= c2)? 1: -1;
}
#endif
} }
int qse_wcsxncasecmp ( int qse_wcsxncasecmp (