NX/VITA: More intelligent strtrim

This commit is contained in:
cypress 2023-11-06 10:49:46 -05:00 committed by GitHub
parent 377fafa815
commit 01993b3e0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}; };
/* /*