diff --git a/harbour/ChangeLog b/harbour/ChangeLog index cf54762e6b..0f1c172651 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -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 diff --git a/harbour/include/harbour.hbx b/harbour/include/harbour.hbx index d37a2159c1..3763899104 100644 --- a/harbour/include/harbour.hbx +++ b/harbour/include/harbour.hbx @@ -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 diff --git a/harbour/src/rtl/chruni.c b/harbour/src/rtl/chruni.c index 021419e1ca..d5951e076b 100644 --- a/harbour/src/rtl/chruni.c +++ b/harbour/src/rtl/chruni.c @@ -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( , , ) -> + */ +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( , , ) -> + */ +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 ); +}