02.03.2011, 03:02
(
Последний раз редактировалось leong124; 04.03.2011 в 05:52.
)
pawn Код:
#if !defined isnull
#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
//Credits for the isnull macro goes to ******, I just use it in the function below.
stock strcmpex(const string1[],const string2[],bool:ignorecase = false,length = cellmax)
{
if(!isnull(string1) && !isnull(string2))
{
new len1 = strlen(string1),len2 = strlen(string2);
if(len1 == len2 || length != cellmax)
{
if(length > len1) length = len1;
if(!ignorecase)
{
for(new i = 0;i < length;i++)
if(string1[i] != string2[i]) return 1;
}
else
{
for(new i = 0;i < length;i++)
if(string1[i] != string2[i])
{
switch(string1[i])
{
case 'A'..'Z','a'..'z':
{
switch(string2[i])
{
case 'A'..'Z','a'..'z': if((string1[i] | 0x20) != (string2[i] | 0x20)) return 1;
default: return 1;
}
}
default: return 1;
}
}
}
return 0;
}
}
else if(isnull(string1) && isnull(string2)) return 0;
return 1;
}
#if defined strcmp
#undef strcmp
#endif
#define strcmp strcmpex
- Faster than the original strcmp when ignoring case in a longer string length.
- Fixed a bug a strcmp that null string will be equal to anything.
- Fixed a crashing bug in strcmp but I forgot the code(May be fixed already)
EDIT:
Now fixed a bug on ignoring case and the fix improved the speed a bit(by around 5%).