tier1/strtools.cpp
int _V_UCS2ToUTF8( const ucs2 *pUCS2, char *pUTF8, int cubDestSizeInBytes )
{
	pUTF8[0] = 0;
#ifdef _WIN32
	// under win32 wchar_t == ucs2, sigh
	int cchResult = WideCharToMultiByte( CP_UTF8, 0, pUCS2, -1, pUTF8, cubDestSizeInBytes, NULL, NULL );
#elif defined(POSIX)
	iconv_t conv_t = iconv_open( "UTF-8", "UCS-2LE" );
	size_t cchResult = -1;
	size_t nLenUnicde = cubDestSizeInBytes;
	size_t nMaxUTF8 = cubDestSizeInBytes;
	char *pIn = (char *)pUCS2;
	char *pOut = (char *)pUTF8;
	if ( conv_t > (iconv_t)0 )
	{
		cchResult = 0;
		cchResult = iconv( conv_t, &pIn, &nLenUnicde, &pOut, &nMaxUTF8 );
		iconv_close( conv_t );
		if ( (int)cchResult < 0 )
			cchResult = 0;
		else
			cchResult = nMaxUTF8;
	}
#endif
	pUTF8[cubDestSizeInBytes - 1] = 0;
	return cchResult;	
}
//-----------------------------------------------------------------------------
// Purpose: Converts a ucs-2 (windows wchar_t) string into a UTF8 (standard) string
//-----------------------------------------------------------------------------
Converts a ucs-2 (windows wchar_t) string into a UTF8 (standard) string
Converts a ucs - 2 ( windows wchar_t ) string into a UTF8 ( standard ) string
int _V_UCS2ToUTF8( const ucs2 *pUCS2, char *pUTF8, int cubDestSizeInBytes )
{
	pUTF8[0] = 0;
#ifdef _WIN32
	int cchResult = WideCharToMultiByte( CP_UTF8, 0, pUCS2, -1, pUTF8, cubDestSizeInBytes, NULL, NULL );
#elif defined(POSIX)
	iconv_t conv_t = iconv_open( "UTF-8", "UCS-2LE" );
	size_t cchResult = -1;
	size_t nLenUnicde = cubDestSizeInBytes;
	size_t nMaxUTF8 = cubDestSizeInBytes;
	char *pIn = (char *)pUCS2;
	char *pOut = (char *)pUTF8;
	if ( conv_t > (iconv_t)0 )
	{
		cchResult = 0;
		cchResult = iconv( conv_t, &pIn, &nLenUnicde, &pOut, &nMaxUTF8 );
		iconv_close( conv_t );
		if ( (int)cchResult < 0 )
			cchResult = 0;
		else
			cchResult = nMaxUTF8;
	}
#endif
	pUTF8[cubDestSizeInBytes - 1] = 0;
	return cchResult;	
}
int _V_UCS2ToUTF8 ( const ucs2 * pUCS2 , char * pUTF8 , int cubDestSizeInBytes ) { pUTF8 [ 0 ] = 0 ; #ifdef _WIN32 int cchResult = WideCharToMultiByte ( CP_UTF8 , 0 , pUCS2 , -1 , pUTF8 , cubDestSizeInBytes , NULL , NULL ) ; #elif defined ( POSIX ) iconv_t conv_t = iconv_open ( " " , " " ) ; size_t cchResult = -1 ; size_t nLenUnicde = cubDestSizeInBytes ; size_t nMaxUTF8 = cubDestSizeInBytes ; char * pIn = ( char * ) pUCS2 ; char * pOut = ( char * ) pUTF8 ; if ( conv_t > ( iconv_t ) 0 ) { cchResult = 0 ; cchResult = iconv ( conv_t , & pIn , & nLenUnicde , & pOut , & nMaxUTF8 ) ; iconv_close ( conv_t ) ; if ( ( int ) cchResult < 0 ) cchResult = 0 ; else cchResult = nMaxUTF8 ; } #endif pUTF8 [ cubDestSizeInBytes - 1 ] = 0 ; return cchResult ; }
Purpose: Converts a ucs-2 (windows wchar_t) string into a UTF8 (standard) string
Purpose : Converts a ucs - 2 ( windows wchar_t ) string into a UTF8 ( standard ) string
// under win32 wchar_t == ucs2, sigh