cwText.h/cpp : Added removeTrailingWhitespace()

This commit is contained in:
kevin 2024-09-19 15:06:27 -04:00
parent 49b4a1430f
commit 05d0c316f4
2 changed files with 27 additions and 1 deletions

View File

@ -185,6 +185,30 @@ const char* cw::lastMatchChar( const char* s, char c )
return lastMatchChar((char*)s,c);
}
char* cw::removeTrailingWhitespace( char* s )
{
char* s0;
unsigned sn;
if( s == nullptr )
return nullptr;
if((sn = textLength(s)) == 0 )
return s;
s0 = s + (sn-1);
for(; s0>=s; --s0)
{
if( !isspace(*s0) )
break;
*s0 = 0;
}
return s;
}
bool cw::isInteger( const char* s )
{
for(; *s; ++s)

View File

@ -70,7 +70,9 @@ namespace cw
// Find the last occurrent of 'c' in s[].
char* lastMatchChar( char* s, char c );
const char* lastMatchChar( const char* s, char c );
const char* lastMatchChar( const char* s, char c );
char* removeTrailingWhitespace( char* s );
bool isInteger( const char* ); // text contains only [0-9]
bool isReal( const char* ); // text contains only [0-9] with one decimal place