I have in front of my eyes right now the Clipper and Harbour results of
a simple Trimtest() function in two different windows, and the results
are identical between the two.
local cTest := chr( 9 ) + ' ' + 'X' + ' ' + chr( 9 )
? 'ltrim ', len( ltrim( cTest ) ) // 3
? 'rtrim ', len( rtrim( cTest ) ) // 5
? 'alltrim', len( alltrim( cTest ) ) // 3
The reason for that is that Clipper's behavior has been investigated
thoroughly and duplicated in Harbour. So the difference between left and
right trimming in Harbour is because of Clipper compatibility (the most
important Harbour cornerstone). Why Clipper's left and right trimming
functions are different regarding white space is anyone's guess ...
In harbour\src\rtl\trim.c you can see the logic behind how the trimming
Ltrim() uses the C function hb_strLTrim() which trims ALL white space
characters. The two leftmost characters are lost.
Rtrim() uses the hb_strRTrimLen() C function which trims either only
chr(32) or all white space characters depending on the 3rd argument
passed from the PRG function calling it. In the case of Rtrim() and
Alltrim() that argument is to only trim chr(32). So Rtrim() loses no
characters in the example above.
Alltrim() calls both C level functions, so the two leftmost characters
The xhb_* variants of the PRG level trimming functions all have that
extra argument as an extension so the application programmer can choose
one or the other trimming options.
This is the macro that is used to determine what is white space in the
cases where all white space characters are trimmed:
#define HB_ISSPACE( c ) ( ( c ) == ' ' || \
( c ) == HB_CHAR_HT || \
( c ) == HB_CHAR_LF || \
( c ) == HB_CHAR_CR )