mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-24 13:55:36 +03:00
strbreak() added
This commit is contained in:
parent
74d424c2a3
commit
1fa97936ff
@ -236,6 +236,9 @@
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\amxxlog.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\CCmd.cpp">
|
||||
<FileConfiguration
|
||||
|
@ -482,6 +482,61 @@ char* format_arguments(AMX *amx, int parm,int& len)
|
||||
return *buffer;
|
||||
}
|
||||
|
||||
//added by BAILOPAN
|
||||
//Takes a string and breaks it into a 1st param and rest params
|
||||
//strbreak(String[], First[], FirstLen, Rest[], RestLen)
|
||||
static cell AMX_NATIVE_CALL strbreak(AMX *amx, cell *params) /* 5 param */
|
||||
{
|
||||
bool quote_flag = false;
|
||||
bool done_flag = false;
|
||||
int left_pos = 0;
|
||||
int right_pos = 0;
|
||||
int l=0;
|
||||
unsigned int i=0;
|
||||
char hold = '"';
|
||||
|
||||
char *string = get_amxstring(amx, params[1], 0, l);
|
||||
char *left = new char[strlen(string)+1];
|
||||
char *right = new char[strlen(string)+1];
|
||||
int LeftMax = params[3];
|
||||
int RightMax = params[5];
|
||||
|
||||
for (i=0; i<strlen(string); i++) {
|
||||
if (string[i] == '"') {
|
||||
quote_flag = true;
|
||||
} else if (string[i] == '"' && quote_flag) {
|
||||
quote_flag = false;
|
||||
}
|
||||
if ((string[i] == ' ') && !quote_flag && !done_flag) {
|
||||
done_flag = true;
|
||||
i++;
|
||||
}
|
||||
if (!done_flag && string[i]!='"') {
|
||||
if (left_pos < LeftMax) {
|
||||
left[left_pos] = string[i];
|
||||
if (left[left_pos] = '\'') {
|
||||
left[left_pos] = hold;
|
||||
}
|
||||
left_pos++;
|
||||
}
|
||||
} else {
|
||||
if (right_pos < RightMax && string[i]!='"') {
|
||||
right[right_pos] = string[i];
|
||||
if (right[right_pos] == '\'') {
|
||||
right[right_pos] = hold;
|
||||
}
|
||||
right_pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
left[left_pos] = '\0';
|
||||
right[right_pos] = '\0';
|
||||
set_amxstring(amx, params[2], left, params[3]);
|
||||
set_amxstring(amx, params[4], right, params[5]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL format_args(AMX *amx, cell *params)
|
||||
{
|
||||
int len;
|
||||
@ -532,6 +587,7 @@ AMX_NATIVE_INFO string_Natives[] = {
|
||||
{ "parse", parse },
|
||||
{ "replace", replace },
|
||||
{ "setc", setc },
|
||||
{ "strbreak", strbreak},
|
||||
{ "strtolower", strtolower },
|
||||
{ "strtoupper", strtoupper },
|
||||
{ "str_to_num", strtonum },
|
||||
|
@ -66,6 +66,16 @@ native setc(src[],len,ch);
|
||||
* Function returns number of parsed parameters. */
|
||||
native parse(const text[], ... );
|
||||
|
||||
/* Gets parameters from text one at a time
|
||||
It breaks a string into the first parameter and the rest of the parameters
|
||||
(A left side and right side of the string)
|
||||
Example: to split text: "^"This is^" the best year",
|
||||
split(text, arg1, len1, arg2, len2)
|
||||
arg1="^"This is^"", arg2="the best year"
|
||||
This more useful than parse() because you can keep breaking
|
||||
any number of arguments */
|
||||
native strbreak(const text[], Left[], leftLen, Right[], rightLen);
|
||||
|
||||
/* Converts all chars in string to lower case. */
|
||||
native strtolower(string[]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user