diff --git a/harbour/ChangeLog b/harbour/ChangeLog index d8e974cee6..136c8d22f9 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,18 @@ The license applies to all entries newer than 2009-04-28. */ +2011-02-20 22:53 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + + contrib/hbct/tests/numline.prg + * contrib/hbct/numline.c + + Added NUMLINE() tests. The results are based on real tests + with CT3, which differ from what CT3 NG states for 'NUMLINE("")' + ! NUMLINE(): fixed to handle LF EOLs (like original CT3) + % NUMLINE(): variable scope plus minor optimization. + ! NUMLINE(): don't strip const when casting. + * NUMLINE(): use HB_CHAR_* constant. + ! NUMLINE(): fixed line counting to be compatible with CT3. + Supposed to fix sf.net #3029405 bug. Please test and review. + 2011-02-20 19:46 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbpost.hbm * config/linux/gcc.mk diff --git a/harbour/contrib/hbct/numline.c b/harbour/contrib/hbct/numline.c index 536615876b..ddccca4417 100644 --- a/harbour/contrib/hbct/numline.c +++ b/harbour/contrib/hbct/numline.c @@ -3,12 +3,12 @@ */ /* - * xHarbour Project source code: - * CT3 numeric functions + * Harbour Project source code: + * CT3 string functions: NUMLINE() * - * NUMLINE() + * Copyright 2011 Viktor Szakats (harbour.01 syenar.hu) * Copyright 2004 Pavel Tsarenko - * www - http://www.xharbour.org + * www - http://www.harbour-project.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -59,28 +59,23 @@ HB_FUNC( NUMLINE ) if( HB_ISCHAR( 1 ) ) { - const char * pcString = hb_parc( 1 ); - const char * pBuffer; HB_ISIZ nStrLen = hb_parclen( 1 ); - HB_ISIZ nLength = hb_parnsdef( 2, 80 ); + const char * pcString = hb_parc( 1 ); + HB_ISIZ nLineLength = hb_parnsdef( 2, 80 ); while( nStrLen > 0 ) { - pBuffer = ( char * ) memchr( pcString, 13, nStrLen ); - if( ! pBuffer ) - pBuffer = pcString + nStrLen; + const char * pBuffer = ( const char * ) memchr( pcString, HB_CHAR_LF, nStrLen ); - if( ( pBuffer - pcString ) > nLength ) - pBuffer = pcString + nLength; + if( ! pBuffer || ( pBuffer - pcString ) > nLineLength ) + pBuffer = pcString + nLineLength; else - { ++pBuffer; - if( *pBuffer == 10 ) - ++pBuffer; - } nStrLen -= pBuffer - pcString; pcString = pBuffer; ++nLines; + if( nStrLen == 0 ) + ++nLines; } } diff --git a/harbour/contrib/hbct/tests/numline.prg b/harbour/contrib/hbct/tests/numline.prg new file mode 100644 index 0000000000..bdde14b556 --- /dev/null +++ b/harbour/contrib/hbct/tests/numline.prg @@ -0,0 +1,29 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * + * Copyright 2011 Viktor Szakats (harbour.01 syenar.hu) + * www - http://harbour-project.org + * + */ + +#include "simpleio.ch" + +PROCEDURE Main() + + ? NUMLINE( "" ) , 0 + ? NUMLINE( "-" ) , 1 + ? NUMLINE( Replicate( "-", 80 ) ) , 2 + ? NUMLINE( Replicate( "-", 160 ) ) , 3 + ? NUMLINE( Replicate( "-", 100 ), 30 ) , 4 + ? NUMLINE( "-" + Chr( 13 ) + Chr( 10 ) ) , 2 + ? NUMLINE( "-" + Chr( 10 ) ) , 2 + ? NUMLINE( "-" + Chr( 13 ) + Chr( 10 ) + "=" ) , 2 + ? NUMLINE( "-" + Chr( 10 ) + "=" ) , 2 + ? NUMLINE( Replicate( "-", 100 ) + Chr( 13 ) + Chr( 10 ), 30 ) , 5 + ? NUMLINE( Replicate( "-", 100 ) + Chr( 10 ), 30 ) , 5 + + RETURN