mirror of
https://github.com/nzp-team/quakespasm.git
synced 2024-11-14 00:11:19 +00:00
NX/VITA: More intelligent strtrim
This commit is contained in:
parent
377fafa815
commit
01993b3e0d
1 changed files with 22 additions and 23 deletions
|
@ -3097,31 +3097,30 @@ string strtrim (string)
|
||||||
*/
|
*/
|
||||||
void PF_strtrim (void)
|
void PF_strtrim (void)
|
||||||
{
|
{
|
||||||
char *m;
|
const char *str = G_STRING (OFS_PARM0);
|
||||||
m = G_STRING(OFS_PARM0);
|
const char *end;
|
||||||
|
char *news;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
char *c;
|
// figure out the new start
|
||||||
char *s;
|
while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r')
|
||||||
c = m;
|
str++;
|
||||||
|
|
||||||
while (c != '\0' && *c == ' ')
|
// figure out the new end.
|
||||||
c++;
|
end = str + strlen (str);
|
||||||
m = c;
|
while (end > str && (end[-1] == ' ' || end[-1] == '\t' || end[-1] == '\n' || end[-1] == '\r'))
|
||||||
|
end--;
|
||||||
|
|
||||||
c = m + strlen (m) - 1;
|
// copy that substring into a tempstring.
|
||||||
while (c >= m)
|
len = end - str;
|
||||||
{
|
if (len >= STRINGTEMP_LENGTH)
|
||||||
if (*c == ' ')
|
len = STRINGTEMP_LENGTH - 1;
|
||||||
*c = '\0';
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
c--;
|
|
||||||
}
|
|
||||||
|
|
||||||
s = PR_GetTempString();
|
news = PR_GetTempString ();
|
||||||
strcpy(s, m);
|
memcpy (news, str, len);
|
||||||
|
news[len] = 0;
|
||||||
|
|
||||||
G_INT(OFS_RETURN) = PR_SetEngineString(s);
|
G_INT (OFS_RETURN) = PR_SetEngineString (news);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue