some of the string functions twilight wanted

This commit is contained in:
David Anderson 2005-07-30 16:47:48 +00:00
parent 5d92972aad
commit cdbfa38391

View File

@ -649,6 +649,75 @@ static cell AMX_NATIVE_CALL amx_trim(AMX *amx, cell *params)
return incr; return incr;
} }
static cell AMX_NATIVE_CALL n_strcat(AMX *amx,cell *params)
{
cell *cdest,*csrc;
cdest = get_amxaddr(amx, params[1]);
csrc = get_amxaddr(amx, params[2]);
int num = params[3];
while (*cdest && num)
{
cdest++;
num--;
}
if (!num)
return 0;
while (*csrc && num)
{
*cdest++ = *csrc++;
num--;
}
*cdest = 0;
return params[3] - num;
}
static cell AMX_NATIVE_CALL n_strcmp(AMX *amx, cell *params)
{
int len;
char *str1 = get_amxstring(amx, params[1], 0, len);
char *str2 = get_amxstring(amx, params[2], 1, len);
if (params[1])
return stricmp(str1, str2);
else
return strcmp(str1, str2);
}
static cell AMX_NATIVE_CALL n_strfind(AMX *amx, cell *params)
{
int len;
char *str = get_amxstring(amx, params[1], 0, len);
int sublen;
char *sub = get_amxstring(amx, params[2], 1, sublen);
bool found = false;
bool igcase = params[3] ? true : false;
if (igcase)
{
for (int i=0; i<len; i++)
{
if (str[i] & (1<<5))
str[i] &= ~(1<<5);
}
for (int i=0; i<sublen; i++)
{
if (str[i] & (1<<5))
str[i] &= ~(1<<5);
}
}
if (params[4] > len)
return -1;
char *pos = &(str[ params[4] ]);
char *find = strstr(str, sub);
if (!find)
return -1;
return (find - str);
}
AMX_NATIVE_INFO string_Natives[] = { AMX_NATIVE_INFO string_Natives[] = {
{ "add", add }, { "add", add },
{ "contain", contain }, { "contain", contain },
@ -677,5 +746,9 @@ AMX_NATIVE_INFO string_Natives[] = {
{ "ucfirst", amx_ucfirst }, { "ucfirst", amx_ucfirst },
{ "strtok", amx_strtok }, { "strtok", amx_strtok },
{ "strlen", amx_strlen }, { "strlen", amx_strlen },
{ "strcat", n_strcat },
{ "strfind", n_strfind },
{ "strcmp", n_strcmp },
{ NULL, NULL } { NULL, NULL }
}; };