mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
public: reimplement COM_TrimSpace, add it to crtlib, add tests for it
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user