mirror of
https://github.com/nzp-team/dquakeplus.git
synced 2024-11-29 07:01:50 +00:00
ACTUALLY more intelligent strtrim
This commit is contained in:
parent
682594721f
commit
1537ce1c36
1 changed files with 33 additions and 19 deletions
|
@ -1245,26 +1245,40 @@ string strtrim (string)
|
||||||
*/
|
*/
|
||||||
void PF_strtrim (void)
|
void PF_strtrim (void)
|
||||||
{
|
{
|
||||||
char *m;
|
int offset, length;
|
||||||
m = G_STRING(OFS_PARM0);
|
int maxoffset; // 2001-10-25 Enhanced temp string handling by Maddes
|
||||||
|
char *str;
|
||||||
char *c;
|
char *end;
|
||||||
c = m;
|
|
||||||
|
|
||||||
while (c == ' ' || c == '\t' || c == '\n' || c == '\r')
|
str = G_STRING(OFS_PARM0);
|
||||||
c++;
|
|
||||||
m = c;
|
// figure out the new start
|
||||||
|
while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r') {
|
||||||
c = m + strlen (m) - 1;
|
offset++;
|
||||||
while (c >= m)
|
str++;
|
||||||
{
|
}
|
||||||
if (*c == ' ')
|
|
||||||
*c = '\0';
|
// figure out the new end.
|
||||||
else
|
end = str + strlen (str);
|
||||||
break;
|
while (end > str && (end[-1] == ' ' || end[-1] == '\t' || end[-1] == '\n' || end[-1] == '\r'))
|
||||||
c--;
|
end--;
|
||||||
}
|
|
||||||
G_INT(OFS_RETURN) = m - pr_strings;
|
length = end - str;
|
||||||
|
|
||||||
|
if (offset < 0)
|
||||||
|
offset = 0;
|
||||||
|
// 2001-10-25 Enhanced temp string handling by Maddes start
|
||||||
|
if (length >= PR_MAX_TEMPSTRING)
|
||||||
|
length = PR_MAX_TEMPSTRING-1;
|
||||||
|
// 2001-10-25 Enhanced temp string handling by Maddes end
|
||||||
|
if (length < 0)
|
||||||
|
length = 0;
|
||||||
|
|
||||||
|
//str += offset;
|
||||||
|
strncpy(pr_string_temp, str, length);
|
||||||
|
pr_string_temp[length] = 0;
|
||||||
|
|
||||||
|
G_INT(OFS_RETURN) = pr_string_temp - pr_strings;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue