mirror of
https://github.com/nzp-team/quakespasm.git
synced 2024-11-22 03:41:07 +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;
|
||||||
char *c;
|
size_t len;
|
||||||
char *s;
|
|
||||||
c = m;
|
|
||||||
|
|
||||||
while (c != '\0' && *c == ' ')
|
|
||||||
c++;
|
|
||||||
m = c;
|
|
||||||
|
|
||||||
c = m + strlen (m) - 1;
|
|
||||||
while (c >= m)
|
|
||||||
{
|
|
||||||
if (*c == ' ')
|
|
||||||
*c = '\0';
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
c--;
|
|
||||||
}
|
|
||||||
|
|
||||||
s = PR_GetTempString();
|
// figure out the new start
|
||||||
strcpy(s, m);
|
while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r')
|
||||||
|
str++;
|
||||||
|
|
||||||
G_INT(OFS_RETURN) = PR_SetEngineString(s);
|
// figure out the new end.
|
||||||
|
end = str + strlen (str);
|
||||||
|
while (end > str && (end[-1] == ' ' || end[-1] == '\t' || end[-1] == '\n' || end[-1] == '\r'))
|
||||||
|
end--;
|
||||||
|
|
||||||
|
// copy that substring into a tempstring.
|
||||||
|
len = end - str;
|
||||||
|
if (len >= STRINGTEMP_LENGTH)
|
||||||
|
len = STRINGTEMP_LENGTH - 1;
|
||||||
|
|
||||||
|
news = PR_GetTempString ();
|
||||||
|
memcpy (news, str, len);
|
||||||
|
news[len] = 0;
|
||||||
|
|
||||||
|
G_INT (OFS_RETURN) = PR_SetEngineString (news);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue