2012-04-24 17:34 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)

* harbour/include/harbour.hbx
  * harbour/src/rtl/chruni.c
    + added HB_BSUBSTR() and HB_USUBSTR()
This commit is contained in:
Przemyslaw Czerpak
2012-04-24 15:34:32 +00:00
parent 5d2675146a
commit 0aeb0d3cae
3 changed files with 102 additions and 0 deletions

View File

@@ -16,6 +16,11 @@
The license applies to all entries newer than 2009-04-28.
*/
2012-04-24 17:34 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* harbour/include/harbour.hbx
* harbour/src/rtl/chruni.c
+ added HB_BSUBSTR() and HB_USUBSTR()
2012-04-24 16:20 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* harbour/include/hbapilng.h
* harbour/src/vm/hvm.c

View File

@@ -326,6 +326,7 @@ DYNAMIC hb_blowfishEncrypt
DYNAMIC hb_blowfishKey
DYNAMIC hb_BPeek
DYNAMIC hb_BPoke
DYNAMIC hb_BSubStr
DYNAMIC hb_BuildDate
DYNAMIC hb_ByteSwapI
DYNAMIC hb_ByteSwapL
@@ -834,6 +835,7 @@ DYNAMIC hb_UPeek
DYNAMIC hb_UPoke
DYNAMIC hb_UserLang
DYNAMIC hb_UserName
DYNAMIC hb_USubStr
DYNAMIC hb_UTCOffset
DYNAMIC hb_utf8Asc
DYNAMIC hb_utf8At

View File

@@ -265,3 +265,98 @@ HB_FUNC( HB_BPOKE )
else
hb_errRT_BASE_SubstR( EG_ARG, 1111, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
/* HB_BSUBSTR( <cString>, <nStart>, <nCount> ) -> <cSubstring>
*/
HB_FUNC( HB_BSUBSTR )
{
PHB_ITEM pText = hb_param( 1, HB_IT_STRING );
int iPCount = hb_pcount();
if( pText && HB_ISNUM( 2 ) && ( iPCount < 3 || HB_ISNUM( 3 ) ) )
{
const char * pszText = hb_itemGetCPtr( pText );
HB_ISIZ nSize = hb_itemGetCLen( pText );
HB_ISIZ nFrom = hb_parns( 2 );
HB_ISIZ nCount = iPCount < 3 ? nSize : hb_parns( 3 );
if( nFrom > 0 )
{
if( --nFrom > nSize )
nCount = 0;
}
if( nCount > 0 )
{
if( nFrom < 0 )
nFrom += nSize;
if( nFrom > 0 )
{
pszText += nFrom;
nSize -= nFrom;
}
if( nCount > nSize )
nCount = nSize;
}
if( nCount > 0 )
{
if( nFrom <= 0 && nCount == nSize )
hb_itemReturn( pText );
else
hb_retclen( pszText, nCount );
}
else
hb_retc_null();
}
else
hb_errRT_BASE_SubstR( EG_ARG, 1110, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
/* HB_USUBSTR( <cString>, <nStart>, <nCount> ) -> <cSubstring>
*/
HB_FUNC( HB_USUBSTR )
{
PHB_ITEM pText = hb_param( 1, HB_IT_STRING );
int iPCount = hb_pcount();
if( pText && HB_ISNUM( 2 ) && ( iPCount < 3 || HB_ISNUM( 3 ) ) )
{
PHB_CODEPAGE cdp = hb_vmCDP();
const char * pszText = hb_itemGetCPtr( pText );
HB_ISIZ nSize = hb_itemGetCLen( pText );
HB_ISIZ nFrom = hb_parns( 2 );
HB_ISIZ nCount = iPCount < 3 ? nSize : hb_parns( 3 );
if( nFrom > 0 )
{
if( --nFrom > nSize )
nCount = 0;
}
if( nCount > 0 )
{
if( nFrom < 0 )
nFrom += hb_cdpTextLen( cdp, pszText, nSize );
if( nFrom > 0 )
{
nFrom = hb_cdpTextPos( cdp, pszText, nSize, nFrom );
pszText += nFrom;
nSize -= nFrom;
}
nCount = hb_cdpTextPos( cdp, pszText, nSize, nCount );
}
if( nCount > 0 )
{
if( nFrom <= 0 && nCount == nSize )
hb_itemReturn( pText );
else
hb_retclen( pszText, nCount );
}
else
hb_retc_null();
}
else
hb_errRT_BASE_SubstR( EG_ARG, 1110, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}