Revision: 12921 http://harbour-project.svn.sourceforge.net/harbour-project/?rev=12921&view=rev Author: druzus Date: 2009-11-17 18:38:12 +0000 (Tue, 17 Nov 2009)
Log Message: ----------- 2009-11-17 19:37 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/Makefile + harbour/include/hbapistr.h * harbour/src/vm/Makefile * harbour/src/vm/hvmall.c + harbour/src/vm/strapi.c + added new C functions to extract strings in different encoding: void * hb_itemGetStr( PHB_ITEM pItem, void * cdp, const char ** pStrPtr, ULONG * pulLen ); void * hb_itemGetStrUTF8( PHB_ITEM pItem, const char ** pStrPtr, ULONG * pulLen ); void * hb_itemGetStrU16( PHB_ITEM pItem, int iEndian, const HB_WCHAR ** pStrPtr, ULONG * pulLen ); extract from given item string in requested encoding and store pointer to this string and its size in characters in last two parameters. These functions return handler which is used to lock memory buffer with result or NULL if given item does not contain string. All not NULL handles returned by above functions have to be free by hb_strfree() function: void hb_strfree( void * hString ); As long as they are not freed memory buffer set in pStrPtr is valid even if other code overwrote given item. The second parameter in hb_itemGetStr() can specify expected CP encoding, i.e.: hStr = hb_itemGetStr( pItem, hb_setGetOSCP(), &pszText, &ulLen ); if( hStr ) { ... hb_strfree( hStr ); } extracts string in encoding set by Set( _SET_OSCODEPAGE, <cCPID> ) The second parameter in hb_itemGetStrU16() define endian encoding and can be one of the following values: #define HB_CDP_ENDIAN_NATIVE 0 #define HB_CDP_ENDIAN_LITTLE 1 #define HB_CDP_ENDIAN_BIG 2 defined in hbapicdp.h + added new C functions to copy part of strings to given buffers in different encoding: ULONG hb_itemCopyStr( PHB_ITEM pItem, void * cdp, char * pStrBuffer, ULONG ulSize ); ULONG hb_itemCopyStrUTF8( PHB_ITEM pItem, char * pStrBuffer, ULONG ulSize ); ULONG hb_itemCopyStrU16( PHB_ITEM pItem, int iEndian, HB_WCHAR * pStrBuffer, ULONG ulSize ); hb_itemCopyStr*() functions works in similar way to hb_itemGetStr*() ones but they copy the strings to given buffer and return the number of characters (not bytes) copied to the buffer. + added new C functions to store given strings in different encoding in HVM item: PHB_ITEM hb_itemPutStrLen( PHB_ITEM pItem, void * cdp, const char * pStr, ULONG ulLen ); PHB_ITEM hb_itemPutStrLenUTF8( PHB_ITEM pItem, const char * pStr, ULONG ulLen ); PHB_ITEM hb_itemPutStrLenU16( PHB_ITEM pItem, int iEndian, const HB_WCHAR * pStr, ULONG ulLen ); These functions accepts strings in different encoding, made some conversions (if necessary and internal string representation in HVM is different) and then store them as HVM string items. + added few extended API functions to operate on strings in different encoding: void * hb_parstr( int iParam, void * cdp, const char ** pStrPtr, ULONG * pulLen ); void * hb_parstr_utf8( int iParam, const char ** pStrPtr, ULONG * pulLen ); void * hb_parstr_u16( int iParam, int iEndian, const HB_WCHAR ** pStrPtr, ULONG * pulLen ); void hb_retstr( void * cdp, const char * szText ); void hb_retstr_utf8( const char * szText ); void hb_retstr_u16( int iEndian, const HB_WCHAR * szText ); void hb_retstrlen( void * cdp, const char * szText, ULONG ulLen ); void hb_retstrlen_utf8( const char * szText, ULONG ulLen ); void hb_retstrlen_u16( int iEndian, const HB_WCHAR * szText, ULONG ulLen ); int hb_storstr( void * cdp, const char * szText, int iParam ); int hb_storstr_utf8( const char * szText, int iParam ); int hb_storstr_u16( int iEndian, const HB_WCHAR * szText, int iParam ); int hb_storstrlen( void * cdp, const char * szText, ULONG ulLen, int iParam ); int hb_storstrlen_utf8( const char * szText, ULONG ulLen, int iParam ); int hb_storstrlen_u16( int iEndian, const HB_WCHAR * szText, ULONG ulLen, int iParam ); They can be used instead of hb_parc*()/hb_retc*()/hb_storc*() ones and allow to easy create code which operates on strings in different encoding, i.e.: HB_FUNC( MY_STRTOUTF8 ) { const char * str; ULONG len; void * h; h = hb_parstr_utf8( 1, &str, &len ); if( h ) { hb_retclen( str, len ); hb_strfree( h ); } } The above functions allows to create code which operates on different string encoding, i.e. UTF8, UCS2/UTF16, some CPs and such code is independent from internal HVM string representation so we can use internally Unicode or not and it will not effect existing code. Modified Paths: -------------- trunk/harbour/ChangeLog trunk/harbour/include/Makefile trunk/harbour/src/vm/Makefile trunk/harbour/src/vm/hvmall.c Added Paths: ----------- trunk/harbour/include/hbapistr.h trunk/harbour/src/vm/strapi.c This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Harbour mailing list (attachment size limit: 40KB) Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour