HB_UTF8CHR( nChar )
HB_UTF8ASC( <cUtf8> ) -> <nUnicode>
HB_UTF8CHR( <nUniVal> ) -> <cUtf8Char>
#include "Fivewin.ch"
FUNCTION MAIN()
? HB_UTF8ASC( "A" )
RETURN NIL
#pragma BEGINDUMP
#include "error.ch"
#include "hbapierr.h"
static BOOL utf8tou16nextchar( UCHAR ucChar, int * n, USHORT * uc )
{
if( *n > 0 )
{
if( ( ucChar & 0xc0 ) != 0x80 )
return FALSE;
*uc = ( *uc << 6 ) | ( ucChar & 0x3f );
( *n )--;
return TRUE;
}
*n = 0;
*uc = ucChar;
if( ucChar >= 0xc0 )
{
if( ucChar < 0xe0 )
{
*uc &= 0x1f;
*n = 1;
}
else if( ucChar < 0xf0 )
{
*uc &= 0x0f;
*n = 2;
}
else if( ucChar < 0xf8 )
{
*uc &= 0x07;
*n = 3;
}
else if( ucChar < 0xfc )
{
*uc &= 0x03;
*n = 4;
}
else if( ucChar < 0xfe )
{
*uc &= 0x01;
*n = 5;
}
}
return TRUE;
}
HB_FUNC( HB_UTF8ASC )
{
const char * pszString = hb_parc( 1 );
if( pszString )
{
HB_SIZE nLen = hb_parclen( 1 );
USHORT wc = 0;
int n = 0;
while( nLen )
{
if( ! utf8tou16nextchar( ( unsigned char ) *pszString, &n, &wc ) )
break;
if( n == 0 )
break;
pszString++;
nLen--;
}
hb_retnint( wc );
}
else
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
#pragma ENDDUMP
local n, c
n := 0xE100
c := HB_UTF8CHR( n )
? HB_UTF8ASC( HB_UTF8CHR( n ) ) == n // --> .T.
? HB_UTF8CHR( HB_UTF8ASC( c ) ) == c // --> .T.
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 53 guests