* *
* partial sync with the 3.4 fork codebase. These are the things
synces for the most part:
- copyright headers
- grammar/typos in comments and some readmes
- comment/whitespace/decorations
- variable scoping in C files
- DO CASE/SWITCH and some other alternate syntax usage
- minimal amount of human readable text in strings
- minor code updates
- HB_TRACE() void * casts for pointers and few other changes to
avoid C compiler warnings
- various other, minor code cleanups
- only Harbour/C code/headers were touched in src, utils, contrib,
include. No 3rd party code, no make files, and with just a few
exceptions, no 'tests' code was touched.
- certain components were not touched were 3.4 diverged too much
already, like f.e. hbmk2, hbssl, hbcurl, hbexpat
- the goal was that no actual program logic should be altered by
these changes. Except some possible minor exceptions, any such
change is probably a bug in this patch.
It's a massive patch, if you find anything broken after it, please
open an Issue with the details. Build test was done on macOS.
The goal is make it easier to see what actual code/logic was changed
in 3.4 compared to 3.2 and to make patches easier to apply in both
ways.
110 lines
2.5 KiB
C
110 lines
2.5 KiB
C
/* Copyright 1999 {list of individual authors and e-mail addresses} */
|
|
|
|
#include "hbapi.h"
|
|
|
|
static const char * hb_strtoken( const char * szText,
|
|
HB_ISIZ nText,
|
|
HB_ISIZ nIndex,
|
|
char cDelimiter,
|
|
HB_ISIZ * pnLen )
|
|
{
|
|
HB_ISIZ nStart;
|
|
HB_ISIZ nEnd = 0;
|
|
HB_ISIZ nCounter = 0;
|
|
|
|
HB_TRACE( HB_TR_DEBUG,
|
|
( "hb_strtoken(%s, %" HB_PFS "d, %" HB_PFS "d, %d, %p)", szText, nText, nIndex,
|
|
( int ) cDelimiter, ( void * ) pnLen ) );
|
|
|
|
do
|
|
{
|
|
nStart = nEnd;
|
|
|
|
if( cDelimiter != ' ' )
|
|
{
|
|
if( szText[ nStart ] == cDelimiter )
|
|
nStart++;
|
|
}
|
|
else
|
|
{
|
|
while( nStart < nText && szText[ nStart ] == cDelimiter )
|
|
nStart++;
|
|
}
|
|
|
|
if( nStart < nText && szText[ nStart ] != cDelimiter )
|
|
{
|
|
nEnd = nStart + 1;
|
|
|
|
while( nEnd < nText && szText[ nEnd ] != cDelimiter )
|
|
nEnd++;
|
|
}
|
|
else
|
|
nEnd = nStart;
|
|
}
|
|
while( nCounter++ < nIndex - 1 && nEnd < nText );
|
|
|
|
if( nCounter < nIndex )
|
|
{
|
|
*pnLen = 0;
|
|
return "";
|
|
}
|
|
else
|
|
{
|
|
*pnLen = nEnd - nStart;
|
|
return szText + nStart;
|
|
}
|
|
}
|
|
|
|
/* returns the nth occurrence of a substring within a token-delimited string */
|
|
HB_FUNC( STRTOKEN )
|
|
{
|
|
const char * szText;
|
|
HB_ISIZ nIndex = hb_parns( 2 );
|
|
char cDelimiter = *hb_parc( 3 );
|
|
HB_ISIZ nLen;
|
|
|
|
if( ! cDelimiter )
|
|
cDelimiter = ' ';
|
|
|
|
szText = hb_strtoken( hb_parc( 1 ), hb_parclen( 1 ), nIndex, cDelimiter, &nLen );
|
|
|
|
hb_storns( nLen, 4 );
|
|
hb_retclen( szText, nLen );
|
|
}
|
|
|
|
/* debug function to dump the ASCII values of an entire string */
|
|
HB_FUNC( STRDUMP )
|
|
{
|
|
const char * szText = hb_parc( 1 );
|
|
HB_ISIZ i, nLength = hb_parclen( 1 );
|
|
|
|
for( i = 0; i < nLength; i++ )
|
|
printf( "%d ", szText[ i ] );
|
|
printf( "\n" );
|
|
}
|
|
|
|
HB_FUNC( ROT13 )
|
|
{
|
|
if( HB_ISCHAR( 1 ) )
|
|
{
|
|
const char * szText = hb_parc( 1 );
|
|
HB_SIZE i, nLen = hb_parclen( 1 );
|
|
char * szResult = ( char * ) hb_xgrab( nLen + 1 );
|
|
|
|
for( i = 0; i < nLen; i++ )
|
|
{
|
|
char c = szText[ i ];
|
|
if( ( c >= 'A' && c <= 'M' ) || ( c >= 'a' && c <= 'm' ) )
|
|
c += 13;
|
|
else if( ( c >= 'N' && c <= 'Z' ) || ( c >= 'n' && c <= 'z' ) )
|
|
c -= 13;
|
|
|
|
szResult[ i ] = c;
|
|
}
|
|
hb_retclen( szResult, nLen );
|
|
hb_xfree( szResult );
|
|
}
|
|
else
|
|
hb_retc_null();
|
|
}
|