diff --git a/cwText.cpp b/cwText.cpp index 2ae2f89..811a8de 100644 --- a/cwText.cpp +++ b/cwText.cpp @@ -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) diff --git a/cwText.h b/cwText.h index 89a8bf1..f749882 100644 --- a/cwText.h +++ b/cwText.h @@ -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