diff --git a/harbour/ChangeLog b/harbour/ChangeLog index da208cf9a2..667caca4a2 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -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( , , [], [] ) -> + hb_BAt( , , [], [] ) -> + 2012-09-03 08:05 UTC+0200 Viktor Szakats (harbour syenar.net) * ChangeLog ! typo diff --git a/harbour/include/harbour.hbx b/harbour/include/harbour.hbx index 857bbf71b7..f4f005f83f 100644 --- a/harbour/include/harbour.hbx +++ b/harbour/include/harbour.hbx @@ -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 diff --git a/harbour/src/rtl/chruni.c b/harbour/src/rtl/chruni.c index 7544c0e193..8e02021567 100644 --- a/harbour/src/rtl/chruni.c +++ b/harbour/src/rtl/chruni.c @@ -456,3 +456,110 @@ HB_FUNC( HB_BRIGHT ) else hb_retc_null(); } + + +/* HB_UAT( , , [], [] ) -> + */ +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( , , [], [] ) -> + */ +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 ); +}