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.
This commit is contained in:
Viktor Szakats
2011-02-20 21:54:15 +00:00
parent 7412a0b97b
commit 546706df5f
3 changed files with 52 additions and 16 deletions

View File

@@ -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

View File

@@ -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 <tpe2.mail.ru>
* 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;
}
}

View File

@@ -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