Antonio Linares wrote:Enrico,
With my change your code is working fine here
I don't understand why it does not work fine for you there
Antonio Linares wrote:Also, I remind you that MemoLine() is very slow. So if you plan to get the lines of a large text, you should avoid it.
We have code in FWH for reading text lines much much faster
cComment := oRs:Fields("Comment"):Value
// Print comments
nLinCnt := MlCount( cComment, 70 ) // 110
IF nLinCnt > 0
FOR x := 1 to nLinCnt
cText := MemoLine( cComment, 70, x ) // 110
oPrint:Say( LINE,(oPrint:nHorzRes()*.02), cText, oFont10 )
Line += oFont10:nHeight
NEXT
Endif
FUNCTION MAIN()
LOCAL cTxt := REPLICATE( "This is a test" + CHR( 13 ) + CHR( 10 ), 10000 )
LOCAL cNew := ""
LOCAL nLines
LOCAL nSec
LOCAL i
nLines = MLCOUNT( cTxt, 1024, , .F., .T. )
? "Lines:", LTRIM( STR( nLines ) )
?
nSec = SECONDS()
FOR i = 1 TO nLines
cNew += ALLTRIM( MEMOLINE( cTxt, 1024, i, , .F., .T. ) ) + CHR( 13 ) + CHR( 10 )
NEXT
? "Seconds:", SECONDS() - nSec
nLines = MLCOUNT( cNew, 1024, , .F., .T. )
? "Lines:", LTRIM( STR( nLines ) )
RETURN NIL
/* MemoLine( <cString>, [ <nLineLength>=79 ],
* [ <nLineNumber>=1 ],
* [ <nTabSize>=4 ], [ <lWrap>=.T. ],
* [ <cEOL>|<acEOLs> ] ) -> <cLine>
*/
TimStone wrote:I will admit I do not test for elapsed time. That is way too theoretical for me.
Antonio Linares wrote:We could compare xHarbour and Harbour and propose to enhance such function as you need it.
HB_FUNC( MEMOLINE )
{
HB_SIZE ulLen, ulLineLength, ulTabSize;
BOOL fWordWrap;
PHB_EOL_INFO pEOLs;
int iEOLs;
const char * pszString = hb_mlGetParams( 1, &ulLen, &ulLineLength,
&ulTabSize, &fWordWrap,
&pEOLs, &iEOLs );
char * szLine;
ULONG ulLine = hb_parnl( 3 );
HB_SIZE ulEnd, ulOffset = ISNUM( 7 ) ? hb_parnl( 7 ) - 1 : 0;
HB_SIZE ulCols = 0;
if( ! pszString )
{
hb_retc( NULL );
return;
}
if( ulLine == 0 )
{
ulLine = 1;
}
while( --ulLine && ulOffset < ulLen )
{
ulOffset = hb_mlGetLine( pszString, ulLen, ulOffset,
ulLineLength, ulTabSize, 0, fWordWrap,
pEOLs, iEOLs, &ulCols, NULL );
}
ulEnd = ulOffset;
if( ulOffset < ulLen )
{
ULONG ulCol = 0;
ulEnd = hb_mlGetLine( pszString, ulLen, ulOffset,
ulLineLength, ulTabSize, 0, fWordWrap,
pEOLs, iEOLs, &ulCols, NULL );
szLine = ( char * ) hb_xgrab( ulLineLength + 1 );
while( ulCol < ulCols )
{
if( pszString[ ulOffset ] == HB_CHAR_HT )
{
HB_SIZE ul = ulTabSize - ( ulCol % ulTabSize );
do
{
szLine[ ulCol++ ] = ' ';
}
while( --ul && ulCol < ulCols );
}
else if( pszString[ ulOffset ] == HB_CHAR_SOFT1 &&
pszString[ ulOffset + 1 ] == HB_CHAR_SOFT2 )
{
ulOffset++;
}
else
{
szLine[ ulCol++ ] = pszString[ ulOffset ];
}
ulOffset++;
}
if( ulCols < ulLineLength )
{
memset( szLine + ulCols, ' ', ( size_t ) ( ulLineLength - ulCols ) );
}
szLine[ ulLineLength ] = 0;
hb_retclen_buffer( szLine, ulLineLength );
}
else
{
hb_retc( NULL );
}
hb_xfree( pEOLs );
if( ISBYREF( 7 ) )
{
hb_stornl( ( LONG ) ulEnd + 1, 7 );
}
}
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 17 guests