2012-09-03 11:57 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)

* harbour/src/rtl/chruni.c
  * harbour/include/harbour.hbx
    + added new functions to operate on unicode and binary strings.
      They work like hb_At() but are CP independent.
         hb_UAt( <cSubString>, <cString>, [<nFrom>], [<nTo>] ) -> <nAt>
         hb_BAt( <cSubString>, <cString>, [<nFrom>], [<nTo>] ) -> <nAt>
This commit is contained in:
Przemyslaw Czerpak
2012-09-03 09:57:48 +00:00
parent 3fd295d332
commit 745aa1eac2
3 changed files with 117 additions and 0 deletions

View File

@@ -16,6 +16,14 @@
The license applies to all entries newer than 2009-04-28.
*/
2012-09-03 11:57 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* harbour/src/rtl/chruni.c
* harbour/include/harbour.hbx
+ added new functions to operate on unicode and binary strings.
They work like hb_At() but are CP independent.
hb_UAt( <cSubString>, <cString>, [<nFrom>], [<nTo>] ) -> <nAt>
hb_BAt( <cSubString>, <cString>, [<nFrom>], [<nTo>] ) -> <nAt>
2012-09-03 08:05 UTC+0200 Viktor Szakats (harbour syenar.net)
* ChangeLog
! typo

View File

@@ -310,6 +310,7 @@ DYNAMIC hb_ATokens
DYNAMIC hb_AtX
DYNAMIC hb_base64Decode
DYNAMIC hb_base64Encode
DYNAMIC hb_BAt
DYNAMIC hb_BChar
DYNAMIC hb_BCode
DYNAMIC hb_bitAnd
@@ -838,6 +839,7 @@ DYNAMIC hb_TToC
DYNAMIC hb_TToD
DYNAMIC hb_TToN
DYNAMIC hb_TToS
DYNAMIC hb_UAt
DYNAMIC hb_UChar
DYNAMIC hb_UCode
DYNAMIC hb_ULeft

View File

@@ -456,3 +456,110 @@ HB_FUNC( HB_BRIGHT )
else
hb_retc_null();
}
/* HB_UAT( <cSubString>, <cString>, [<nFrom>], [<nTo>] ) -> <nAt>
*/
HB_FUNC( HB_UAT )
{
PHB_ITEM pSub = hb_param( 1, HB_IT_STRING );
PHB_ITEM pText = hb_param( 2, HB_IT_STRING );
if( pText && pSub )
{
PHB_CODEPAGE cdp = hb_vmCDP();
const char * pszText = hb_itemGetCPtr( pText );
HB_SIZE nTextLength = hb_itemGetCLen( pText );
HB_SIZE nStart = hb_parns( 3 );
HB_SIZE nFrom, nTo, nPos = 0;
if( nStart <= 1 )
nStart = nFrom = 0;
else
nFrom = hb_cdpTextPos( cdp, pszText, nTextLength, --nStart );
if( nFrom < nTextLength )
{
pszText += nFrom;
nTextLength -= nFrom;
if( HB_ISNUM( 4 ) )
{
nTo = hb_parns( 4 );
if( nTo <= nStart )
nTo = 0;
else
{
nTo -= nStart;
nTo = hb_cdpTextPos( cdp, pszText, nTextLength, nTo );
if( nTo > nTextLength )
nTo = nTextLength;
}
}
else
nTo = nTextLength;
if( nTo > 0 )
{
nPos = hb_strAt( hb_itemGetCPtr( pSub ), hb_itemGetCLen( pSub ),
pszText, nTo );
if( nPos > 0 )
nPos = hb_cdpTextLen( cdp, pszText, nPos - 1 ) + 1 + nStart;
}
}
hb_retns( nPos );
}
else
hb_errRT_BASE_SubstR( EG_ARG, 1108, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
/* HB_BAT( <cSubString>, <cString>, [<nFrom>], [<nTo>] ) -> <nAt>
*/
HB_FUNC( HB_BAT )
{
PHB_ITEM pSub = hb_param( 1, HB_IT_STRING );
PHB_ITEM pText = hb_param( 2, HB_IT_STRING );
if( pText && pSub )
{
const char * pszText = hb_itemGetCPtr( pText );
HB_SIZE nTextLength = hb_itemGetCLen( pText );
HB_SIZE nStart = hb_parns( 3 );
HB_SIZE nFrom, nTo, nPos = 0;
if( nStart <= 1 )
nStart = nFrom = 0;
else
nFrom = --nStart;
if( nFrom < nTextLength )
{
pszText += nFrom;
nTextLength -= nFrom;
if( HB_ISNUM( 4 ) )
{
nTo = hb_parns( 4 );
if( nTo <= nStart )
nTo = 0;
else
{
nTo -= nStart;
if( nTo > nTextLength )
nTo = nTextLength;
}
}
else
nTo = nTextLength;
if( nTo > 0 )
{
nPos = hb_strAt( hb_itemGetCPtr( pSub ), hb_itemGetCLen( pSub ),
pszText, nTo );
if( nPos > 0 )
nPos += nFrom;
}
}
hb_retns( nPos );
}
else
hb_errRT_BASE_SubstR( EG_ARG, 1108, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}