From 79f927107368e0d3b03cfab3d8a3fb528ef9f9f7 Mon Sep 17 00:00:00 2001 From: Eddie Runia Date: Sat, 12 Jun 1999 16:04:58 +0000 Subject: [PATCH] see changelog --- harbour/ChangeLog | 4 ++++ harbour/source/rtl/strings.c | 28 +++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index a355e4cc6f..ae2ab1a79d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,7 @@ +19990612-17:00 CET Matthew Hamilton + * source/rtl/strings.c + Extended syntax for alltrim and rtrim + 19990612-14:10 CET Eddie Runia * source/rtl/dir.c month started with 0 (Jan). Harbour months start with 1. diff --git a/harbour/source/rtl/strings.c b/harbour/source/rtl/strings.c index b4b55478c4..b02e0d3686 100644 --- a/harbour/source/rtl/strings.c +++ b/harbour/source/rtl/strings.c @@ -106,22 +106,34 @@ HARBOUR HB_LTRIM( void ) } /* returns szText and the new length in lLen */ -ULONG hb_strRTrimLen( char *szText, ULONG lLen ) +ULONG hb_strRTrimLen( char *szText, ULONG lLen, BOOL bAnySpace ) { - while( lLen && szText[lLen - 1] == ' ' ) - lLen--; + if( bAnySpace ) + { + while( lLen && HB_ISSPACE(szText[lLen - 1]) ) + lLen--; + } + else + { + while( lLen && szText[lLen - 1] == ' ' ) + lLen--; + } return lLen; } + /* trims trailing spaces from a string */ /* TEST: QOUT( "rtrim( ' hello world ' ) = '" + rtrim( ' hello world ' ) + "'" ) */ HARBOUR HB_RTRIM( void ) { - if( _pcount() == 1 ) + if( _pcount() > 0 ) { PHB_ITEM pText = _param(1, IT_STRING); if( pText ) - _retclen(pText->value.szText, hb_strRTrimLen(pText->value.szText, pText->wLength)); + { + BOOL bAnySpace = (_pcount() > 1? _parl(2): 0); + _retclen(pText->value.szText, hb_strRTrimLen(pText->value.szText, pText->wLength, bAnySpace)); + } else /* Clipper doesn't error */ _retc(""); @@ -149,7 +161,10 @@ HARBOUR HB_ALLTRIM( void ) if( _pcount() > 0 ) { char *szText = _parc(1); - ULONG lLen = hb_strRTrimLen(szText, _parclen(1)); + BOOL bAnySpace = (_pcount() > 1? _parl(2): 0); + ULONG lLen; + + lLen = hb_strRTrimLen(szText, _parclen(1), bAnySpace); szText = hb_strLTrim(szText, &lLen); @@ -1165,4 +1180,3 @@ HARBOUR HB_STR( void ) _errRelease(pError); } } -