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,33 +649,106 @@ 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 },
{ "containi", containi }, { "containi", containi },
{ "copy", copy }, { "copy", copy },
{ "copyc", copyc }, { "copyc", copyc },
{ "equal", equal }, { "equal", equal },
{ "equali", equali }, { "equali", equali },
{ "format", format }, { "format", format },
{ "format_args", format_args }, { "format_args", format_args },
{ "isdigit", is_digit }, { "isdigit", is_digit },
{ "isalnum", is_alnum }, { "isalnum", is_alnum },
{ "isspace", is_space }, { "isspace", is_space },
{ "isalpha", is_alpha }, { "isalpha", is_alpha },
{ "num_to_str", numtostr }, { "num_to_str", numtostr },
{ "numtostr", numtostr }, { "numtostr", numtostr },
{ "parse", parse }, { "parse", parse },
{ "replace", replace }, { "replace", replace },
{ "setc", setc }, { "setc", setc },
{ "strbreak", strbreak}, { "strbreak", strbreak},
{ "strtolower", strtolower }, { "strtolower", strtolower },
{ "strtoupper", strtoupper }, { "strtoupper", strtoupper },
{ "str_to_num", strtonum }, { "str_to_num", strtonum },
{ "strtonum", strtonum }, { "strtonum", strtonum },
{ "trim", amx_trim }, { "trim", amx_trim },
{ "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 }
}; };