check.hb, RTrimEOL() function

70 views
Skip to first unread message

Luigi Ferraris

unread,
Jun 28, 2021, 1:13:26 PM6/28/21
to Harbour Developers
Hi friends,
I was reading harbour/bin/check.hb and I found this function
STATIC FUNCTION RTrimEOL( cFile )

   DO WHILE Right( cFile, 1 ) $ Chr( 13 ) + Chr( 10 )
      cFile := hb_StrShrink( cFile, 1 )
   ENDDO

   RETURN cFile


If this function serve to remove all DOS eol from the end of a string, I believe is wrong.
Basically, because CHR(13) + CHR(10) length is 2 and not 1.

So, I think must be changed to
STATIC FUNCTION RTrimEOL( cFile )

   DO WHILE Right( cFile, 2 ) $ Chr( 13 ) + Chr( 10 )
      cFile := hb_StrShrink( cFile, 2 )
   ENDDO

   RETURN cFile


Best regards
Luigi Ferraris

Klas Engwall

unread,
Jun 28, 2021, 2:13:04 PM6/28/21
to harbou...@googlegroups.com
Hi Luigi,

No. Please think twice before reporting "bugs". And do check if your
assumption is right or wrong. The RTrimEOL() function is supposed to
trim all variants of chr( 13 ) and/or chr( 10 ) line endings -
DOS/Windows, Unix, old MAC - and not just DOS/Windows. See the simple
test below.

Regards,
Klas

//----------------------------

proc main()

? len( RTrimEOL( 'Luigi' + Chr( 13 ) + Chr( 10 ) + Chr( 13 ) +;
Chr( 10 ) + Chr( 10 ) + Chr( 10 ) ) )

return

FUNCTION RTrimEOL( cFile )

DO WHILE Right( cFile, 1 ) $ Chr( 13 ) + Chr( 10 )
cFile := hb_StrShrink( cFile, 1 )
ENDDO

RETURN cFile

//----------------------------

Den 2021-06-28 kl. 18:52, skrev Luigi Ferraris:
> Hi friends,
> I was reading harbour/bin/check.hb and I found this function
> STATIC FUNCTION RTrimEOL( cFile )
>
>    DO WHILE Right( cFile, 1 ) $ Chr( 13 ) + Chr( 10 )
>       cFile := hb_StrShrink( cFile, 1 )
>    ENDDO
>
>    RETURN cFile
>
> *If* this function *serve to remove all DOS eol* from the end of a

Luigi Ferraris

unread,
Jun 29, 2021, 12:04:07 PM6/29/21
to Harbour Developers
Hi Klas,
I'm sorry to wasted your time.
Regards,
Luigi
Reply all
Reply to author
Forward
0 new messages