revised moo_compucharsucstr() and similar functions
This commit is contained in:
parent
5474ae242d
commit
8f69172898
@ -109,66 +109,52 @@ int moo_compucbcstr (const moo_uch_t* str1, const moo_bch_t* str2)
|
||||
|
||||
int moo_compucharsucstr (const moo_uch_t* str1, moo_oow_t len, const moo_uch_t* str2)
|
||||
{
|
||||
const moo_uch_t* end = str1 + len;
|
||||
while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++;
|
||||
|
||||
if (str1 == end)
|
||||
{
|
||||
return (*str2 == '\0')? 0: -1;
|
||||
}
|
||||
else /* str1 < end */
|
||||
{
|
||||
/* for "abc\0" of length 4 vs "abc", the fourth character
|
||||
* of the first string is equal to the terminating null of
|
||||
* the second string. the first string is still considered
|
||||
* bigger */
|
||||
return (*str1 >= *str2)? 1: -1;
|
||||
const moo_uch_t* end = str1 + len;
|
||||
while (str1 < end && *str2 != '\0')
|
||||
{
|
||||
if (*str1 != *str2) return (*str1 > *str2)? 1: -1;
|
||||
str1++; str2++;
|
||||
}
|
||||
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
|
||||
}
|
||||
|
||||
int moo_compucharsbcstr (const moo_uch_t* str1, moo_oow_t len, const moo_bch_t* str2)
|
||||
{
|
||||
const moo_uch_t* end = str1 + len;
|
||||
while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++;
|
||||
if (str1 == end)
|
||||
while (str1 < end && *str2 != '\0')
|
||||
{
|
||||
return (*str2 == '\0')? 0: -1;
|
||||
}
|
||||
else /* str1 < end */
|
||||
{
|
||||
return (*str1 >= *str2)? 1: -1;
|
||||
if (*str1 != *str2) return (*str1 > *str2)? 1: -1;
|
||||
str1++; str2++;
|
||||
}
|
||||
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
|
||||
}
|
||||
|
||||
int moo_compbcharsbcstr (const moo_bch_t* str1, moo_oow_t len, const moo_bch_t* str2)
|
||||
{
|
||||
const moo_bch_t* end = str1 + len;
|
||||
while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++;
|
||||
if (str1 == end)
|
||||
while (str1 < end && *str2 != '\0')
|
||||
{
|
||||
return (*str2 == '\0')? 0: -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (*str1 >= *str2)? 1: -1;
|
||||
if (*str1 != *str2) return (*str1 > *str2)? 1: -1;
|
||||
str1++; str2++;
|
||||
}
|
||||
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
|
||||
}
|
||||
|
||||
int moo_compbcharsucstr (const moo_bch_t* str1, moo_oow_t len, const moo_uch_t* str2)
|
||||
{
|
||||
const moo_bch_t* end = str1 + len;
|
||||
while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++;
|
||||
if (str1 == end)
|
||||
while (str1 < end && *str2 != '\0')
|
||||
{
|
||||
return (*str2 == '\0')? 0: -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (*str1 >= *str2)? 1: -1;
|
||||
if (*str1 != *str2) return (*str1 > *str2)? 1: -1;
|
||||
str1++; str2++;
|
||||
}
|
||||
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
|
||||
}
|
||||
|
||||
|
||||
void moo_copyuchars (moo_uch_t* dst, const moo_uch_t* src, moo_oow_t len)
|
||||
{
|
||||
/* take note of no forced null termination */
|
||||
|
Loading…
Reference in New Issue
Block a user