Files
harbour-core/harbour/contrib/hbmisc/stringsx.c
Przemyslaw Czerpak 86333ba271 2008-09-18 07:21 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbthread.h
    * use assembler version of atomic inc/dec operation in all x86 based
      GCC builds - it should noticeable improve OS2 MT build speed,
      please test.

  * harbour/include/hbcomp.h
  * harbour/include/hbapicdp.h
  * harbour/include/hbcompdf.h
  * harbour/include/hbgtcore.h
  * harbour/include/hbapifs.h
  * harbour/include/hbwince.h
  * harbour/include/hbexpra.c
  * harbour/include/hbexprop.h
  * harbour/include/hbmacro.h
  * harbour/include/hbapigt.h
  * harbour/include/hbapi.h
  * harbour/include/hbapiitm.h
  * harbour/include/hbexprb.c
  * harbour/source/pp/ppcore.c
  * harbour/source/pp/hbpp.c
  * harbour/source/vm/macro.c
  * harbour/source/vm/cmdarg.c
  * harbour/source/vm/arrays.c
  * harbour/source/vm/extrap.c
  * harbour/source/vm/memvars.c
  * harbour/source/vm/eval.c
  * harbour/source/vm/extend.c
  * harbour/source/vm/set.c
  * harbour/source/main/harbour.c
  * harbour/source/common/hbfsapi.c
  * harbour/source/common/reserved.c
  * harbour/source/common/expropt1.c
  * harbour/source/macro/macro.yyc
  * harbour/source/macro/macro.y
  * harbour/source/macro/macro.yyh
  * harbour/source/macro/macrolex.c
  * harbour/source/rtl/gtdos/gtdos.c
  * harbour/source/rtl/gtwin/gtwin.c
  * harbour/source/rtl/gtxwc/gtxwc.c
  * harbour/source/rtl/gtos2/gtos2.c
  * harbour/source/rtl/hbgtcore.c
  * harbour/source/rtl/cdpapi.c
  * harbour/source/rtl/gtcrs/gtcrs.c
  * harbour/source/rtl/hbtoken.c
  * harbour/source/rtl/gtchrmap.c
  * harbour/source/rtl/gtstd/gtstd.c
  * harbour/source/rtl/gtsln/mousesln.c
  * harbour/source/rtl/gtsln/gtsln.c
  * harbour/source/rtl/gtsln/kbsln.c
  * harbour/source/rtl/gttrm/gttrm.c
  * harbour/source/rtl/gtpca/gtpca.c
  * harbour/source/rtl/hbhex.c
  * harbour/source/rtl/gtgui/gtgui.c
  * harbour/source/rtl/gt_tpl/gt_tpl.c
  * harbour/source/rtl/gtcgi/gtcgi.c
  * harbour/source/rtl/gtwvt/gtwvt.c
  * harbour/source/rtl/strtran.c
  * harbour/source/rtl/hbinet.c
  * harbour/source/rtl/gtapi.c
  * harbour/source/rtl/filesys.c
  * harbour/source/rdd/dbfntx/dbfntx1.c
  * harbour/source/rdd/dbsql.c
  * harbour/source/rdd/dbfcdx/dbfcdx1.c
  * harbour/source/rdd/dbffpt/dbffpt1.c
  * harbour/source/rdd/hbsix/sxfname.c
  * harbour/source/compiler/ppcomp.c
  * harbour/source/compiler/hbmain.c
  * harbour/source/compiler/cmdcheck.c
  * harbour/source/compiler/hbdbginf.c
  * harbour/source/compiler/genc.c
  * harbour/source/compiler/hbident.c
  * harbour/source/compiler/hbusage.c
  * harbour/source/compiler/gencc.c
  * harbour/source/compiler/harbour.yyc
  * harbour/source/compiler/harbour.y
  * harbour/contrib/gtalleg/gtalleg.c
  * harbour/contrib/hbct/charlist.c
  * harbour/contrib/hbct/charmix.c
  * harbour/contrib/hbct/screen1.c
  * harbour/contrib/hbct/atrepl.c
  * harbour/contrib/xhb/hboutdbg.c
  * harbour/contrib/xhb/hbxml.c
  * harbour/contrib/xhb/hbxml.h
  * harbour/contrib/hbgt/strexpan.c
  * harbour/contrib/hbsqlit3/sqlite3/sqlite3.c
  * harbour/contrib/gtwvg/gtwvg.c
  * harbour/contrib/hbclipsm/status.c
  * harbour/contrib/hbclipsm/gauge.c
  * harbour/contrib/hbmisc/stringsx.c
  * harbour/contrib/hbtip/utils.c
  * harbour/contrib/hbgf/hbgfgtk/msginfo.c
  * harbour/contrib/hbgf/hbgfgtk/harbgtk.h
  * harbour/contrib/hbbmcdx/bmdbfcdx.c
  * harbour/utils/hbmake/hbmgauge.c
    * use const char * instead of char * in places which should be marked
      as const
2008-09-18 05:23:49 +00:00

110 lines
2.3 KiB
C

/*
* $Id$
*/
#include "hbapi.h"
/* TODO: search this file for TODO and find 'em! */
static const char *hb_strtoken(char *szText,
long lText,
long lIndex,
char cDelimiter,
long *lLen)
{
long wStart;
long wEnd = 0;
long 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;
long lIndex = hb_parnl(2);
char cDelimiter = *hb_parc(3);
long 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 )
{
char *szText = hb_parc(1);
long i, lLength = hb_parclen(1);
for( i = 0; i < lLength; i++ )
printf("%d ", szText[i]);
printf("\n");
}
HB_FUNC( ROT13 )
{
if( ISCHAR(1) )
{
char *szText = hb_parc( 1 );
ULONG 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);
}