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