revised moo_compucharsucstr() and similar functions
This commit is contained in:
parent
5474ae242d
commit
8f69172898
@ -3343,7 +3343,7 @@ static pf_t pftab[] =
|
|||||||
{ "Apex_addToBeFinalized", { pf_add_to_be_finalized, 0, 0 } },
|
{ "Apex_addToBeFinalized", { pf_add_to_be_finalized, 0, 0 } },
|
||||||
{ "Apex_basicAt:", { moo_pf_basic_at, 1, 1 } },
|
{ "Apex_basicAt:", { moo_pf_basic_at, 1, 1 } },
|
||||||
{ "Apex_basicAt:put:", { moo_pf_basic_at_put, 2, 2 } },
|
{ "Apex_basicAt:put:", { moo_pf_basic_at_put, 2, 2 } },
|
||||||
{ "Apex_basicFillFrom:with:count:", { moo_pf_basic_fill, 3, 3 } },
|
{ "Apex_basicFillFrom:with:count:", { moo_pf_basic_fill, 3, 3 } },
|
||||||
{ "Apex_basicNew", { moo_pf_basic_new, 0, 0 } },
|
{ "Apex_basicNew", { moo_pf_basic_new, 0, 0 } },
|
||||||
{ "Apex_basicNew:", { moo_pf_basic_new, 1, 1 } },
|
{ "Apex_basicNew:", { moo_pf_basic_new, 1, 1 } },
|
||||||
{ "Apex_basicShiftFrom:to:count:", { moo_pf_basic_shift, 3, 3 } },
|
{ "Apex_basicShiftFrom:to:count:", { moo_pf_basic_shift, 3, 3 } },
|
||||||
|
@ -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)
|
int moo_compucharsucstr (const moo_uch_t* str1, moo_oow_t len, const moo_uch_t* str2)
|
||||||
{
|
{
|
||||||
|
/* 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 */
|
||||||
const moo_uch_t* end = str1 + len;
|
const moo_uch_t* end = str1 + len;
|
||||||
while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++;
|
while (str1 < end && *str2 != '\0')
|
||||||
|
|
||||||
if (str1 == end)
|
|
||||||
{
|
{
|
||||||
return (*str2 == '\0')? 0: -1;
|
if (*str1 != *str2) return (*str1 > *str2)? 1: -1;
|
||||||
}
|
str1++; str2++;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
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)
|
int moo_compucharsbcstr (const moo_uch_t* str1, moo_oow_t len, const moo_bch_t* str2)
|
||||||
{
|
{
|
||||||
const moo_uch_t* end = str1 + len;
|
const moo_uch_t* end = str1 + len;
|
||||||
while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++;
|
while (str1 < end && *str2 != '\0')
|
||||||
if (str1 == end)
|
|
||||||
{
|
{
|
||||||
return (*str2 == '\0')? 0: -1;
|
if (*str1 != *str2) return (*str1 > *str2)? 1: -1;
|
||||||
}
|
str1++; str2++;
|
||||||
else /* str1 < end */
|
|
||||||
{
|
|
||||||
return (*str1 >= *str2)? 1: -1;
|
|
||||||
}
|
}
|
||||||
|
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)
|
int moo_compbcharsbcstr (const moo_bch_t* str1, moo_oow_t len, const moo_bch_t* str2)
|
||||||
{
|
{
|
||||||
const moo_bch_t* end = str1 + len;
|
const moo_bch_t* end = str1 + len;
|
||||||
while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++;
|
while (str1 < end && *str2 != '\0')
|
||||||
if (str1 == end)
|
|
||||||
{
|
{
|
||||||
return (*str2 == '\0')? 0: -1;
|
if (*str1 != *str2) return (*str1 > *str2)? 1: -1;
|
||||||
}
|
str1++; str2++;
|
||||||
else
|
|
||||||
{
|
|
||||||
return (*str1 >= *str2)? 1: -1;
|
|
||||||
}
|
}
|
||||||
|
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)
|
int moo_compbcharsucstr (const moo_bch_t* str1, moo_oow_t len, const moo_uch_t* str2)
|
||||||
{
|
{
|
||||||
const moo_bch_t* end = str1 + len;
|
const moo_bch_t* end = str1 + len;
|
||||||
while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++;
|
while (str1 < end && *str2 != '\0')
|
||||||
if (str1 == end)
|
|
||||||
{
|
{
|
||||||
return (*str2 == '\0')? 0: -1;
|
if (*str1 != *str2) return (*str1 > *str2)? 1: -1;
|
||||||
}
|
str1++; str2++;
|
||||||
else
|
|
||||||
{
|
|
||||||
return (*str1 >= *str2)? 1: -1;
|
|
||||||
}
|
}
|
||||||
|
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void moo_copyuchars (moo_uch_t* dst, const moo_uch_t* src, moo_oow_t len)
|
void moo_copyuchars (moo_uch_t* dst, const moo_uch_t* src, moo_oow_t len)
|
||||||
{
|
{
|
||||||
/* take note of no forced null termination */
|
/* take note of no forced null termination */
|
||||||
|
Loading…
Reference in New Issue
Block a user