Files
harbour-core/harbour/contrib/hbmisc/stringsx.c
Viktor Szakats 9b462b15d0 2010-01-15 17:33 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* src/vm/cmdarg.c
  * contrib/hbct/disk.c
    % Using HB_SIZEOFARRAY() instead of repeating declaration size.

  * src/vm/maindllp.c
  * src/vm/extend.c
  * include/hbtypes.h
  * include/hbapi.h
    + 'parinfa' retval ULONG -> HB_SIZE

  * src/vm/arrayshb.c
  * src/rtl/substr.c
  * src/rtl/replic.c
  * src/rtl/padr.c
  * src/rtl/padc.c
  * src/rtl/strtran.c
  * src/rtl/padl.c
  * src/rtl/lang.c
  * src/rtl/right.c
  * src/rtl/left.c
  * src/rtl/space.c
  * src/rtl/hbstrsh.c
  * src/rtl/rat.c
  * contrib/hbct/charsprd.c
  * contrib/xhb/xhbarr.c
  * contrib/hbpgsql/postgres.c
  * contrib/hbclipsm/stack.c
  * contrib/hbmisc/stringsx.c
    + 'long' -> HB_ISIZ

  * src/common/hbwince.c
  * include/hbwince.h
  * contrib/xhb/xhbat.c
  * contrib/xhb/cstructc.c
    + 'unsigned long' -> HB_SIZE

  * src/rtl/fstemp.c
  * src/rtl/net.c
    ! L'x' -> TEXT( 'x' ).
      'L' was used also in non-UNICODE mode, which doesn't seem right.

  * src/rtl/diskspac.c
  * contrib/hbct/disk.c
  * contrib/hbwin/win_com.c
  * contrib/hbwin/win_prn3.c
    * TCHAR literals enclosed inside TEXT() macro.

  * contrib/hbwin/win_prn1.c
    ! WIN_GETPRINTERFONTNAME(): Fixed buffer overrun in UNICODE
      mode for font names longer than 64 bytes.
      [TOMERGE 2.0]

  * ChangeLog
    + Added two missed changed to this entry:
      2010-01-15 12:01 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
        * include/hbdefs.h
          + Added HB_ISIZ temporary type to mark string/array/hash 
            index/length variable already using signed 'long' type.
            This will have to converted to HB_SIZE, one HB_SIZE
            gets also mapped to 'long'.
          * HB_FATTR mapped to HB_U32 (was: unsigned long)
2010-01-15 16:39:54 +00:00

108 lines
2.3 KiB
C

/*
* $Id$
*/
#include "hbapi.h"
static const char *hb_strtoken(const char *szText,
HB_ISIZ lText,
HB_ISIZ lIndex,
char cDelimiter,
HB_ISIZ *lLen)
{
HB_ISIZ wStart;
HB_ISIZ wEnd = 0;
HB_ISIZ wCounter = 0;
HB_TRACE(HB_TR_DEBUG, ("hb_strtoken(%s, %ld, %ld, %d, %p)", szText, lText, lIndex, (int) cDelimiter, lLen));
do
{
wStart = wEnd;
if( cDelimiter != ' ' )
{
if( szText[wStart] == cDelimiter )
wStart++;
}
else
{
while( wStart < lText && szText[wStart] == cDelimiter )
wStart++;
}
if( wStart < lText && szText[wStart] != cDelimiter )
{
wEnd = wStart + 1;
while( wEnd < lText && szText[wEnd] != cDelimiter )
wEnd++;
}
else
wEnd = wStart;
} while( wCounter++ < lIndex - 1 && wEnd < lText );
if( wCounter < lIndex )
{
*lLen = 0;
return "";
}
else
{
*lLen = wEnd - wStart;
return szText + wStart;
}
}
/* returns the nth occurence of a substring within a token-delimited string */
HB_FUNC( STRTOKEN )
{
const char *szText;
HB_ISIZ lIndex = hb_parnl(2);
char cDelimiter = *hb_parc(3);
HB_ISIZ lLen;
if( !cDelimiter )
cDelimiter = ' ';
szText = hb_strtoken(hb_parc(1), hb_parclen(1), lIndex, cDelimiter, &lLen);
hb_stornl(lLen, 4);
hb_retclen(szText, lLen);
}
/* debug function to dump the ASCII values of an entire string */
HB_FUNC( STRDUMP )
{
const char *szText = hb_parc(1);
HB_ISIZ i, lLength = hb_parclen(1);
for( i = 0; i < lLength; i++ )
printf("%d ", szText[i]);
printf("\n");
}
HB_FUNC( ROT13 )
{
if( HB_ISCHAR(1) )
{
const char *szText = hb_parc( 1 );
HB_SIZE i, lLen = hb_parclen( 1 );
char *szResult = (char*)hb_xgrab(lLen + 1);
for( i = 0; i < lLen; 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, lLen);
hb_xfree(szResult);
}
else
hb_retc_null();
}