public: reimplement COM_TrimSpace, add it to crtlib, add tests for it

This commit is contained in:
Alibek Omarov
2026-02-28 00:05:35 +05:00
parent 62c547570a
commit 9a285986c4
7 changed files with 58 additions and 51 deletions

View File

@@ -887,3 +887,24 @@ int matchpattern_with_separator( const char *in, const char *pattern, qboolean c
return 1; // success
}
void COM_TrimSpace( char *dst, const char *src, size_t size )
{
if( !dst || !src || !size )
return;
// remove spaces from the start
for( ; *src && isspace( *src ); src++ );
int len = Q_strlen( src );
// remove spaces from the end
for( ; len > 0 && isspace( src[len - 1] ); len-- );
if( len > 0 )
{
// + 1 to fit null terminator in strlcpy
Q_strncpy( dst, src, Q_min( size, len + 1 ));
}
else
dst[0] = 0;
}