Page 1 of 2
AscW() function
Posted: Tue Jun 11, 2019 10:57 am
by Natter
Hi, all !
VBA (Excel) has an AscW() function. It is used to obtain the Unicode character code. How do I do this on FW ?
Re: AscW() function
Posted: Tue Jun 11, 2019 1:20 pm
by nageswaragunupudi
Please try
Maybe that is what you are looking for.
Re: AscW() function
Posted: Tue Jun 11, 2019 1:31 pm
by AntoninoP
AscW return the unicode value from character or string. I think the Harbour version is HB_UTF8ASC:
Code: Select all
HB_UTF8ASC( <cUtf8> ) -> <nUnicode>
HB_UTF8CHR is:
Code: Select all
HB_UTF8CHR( <nUniVal> ) -> <cUtf8Char>
Re: AscW() function
Posted: Tue Jun 11, 2019 1:34 pm
by nageswaragunupudi
Yes, Mr. Antonio
And thanks for the correction.
Re: AscW() function
Posted: Tue Jun 11, 2019 1:42 pm
by Natter
Yes, the HB_UTF8Asc() function suits me, but it is not available for FWH18.06
Re: AscW() function
Posted: Tue Jun 11, 2019 1:44 pm
by nageswaragunupudi
This is not FWH function.
This is a Harbour function available both in Harbour and xHarbour.
Re: AscW() function
Posted: Tue Jun 11, 2019 2:53 pm
by Natter
I downloaded xHarbour Binaries 1.2.3 Rev. 10252 for BCC 5.8.2 with xharbour.org But when linking the hb_utf8asc function is not detected
Re: AscW() function
Posted: Tue Jun 11, 2019 3:09 pm
by Enrico Maria Giordano
I confirm: there is no hb_utf8asc() function in xHarbour. I can try to add it to xHarbour, if you really need it.
EMG
Re: AscW() function
Posted: Tue Jun 11, 2019 4:48 pm
by Natter
Yes, I do. I will be very grateful to you
Re: AscW() function
Posted: Tue Jun 11, 2019 5:18 pm
by Enrico Maria Giordano
Ok, I'll see what I can do...
EMG
Re: AscW() function
Posted: Tue Jun 11, 2019 9:15 pm
by Enrico Maria Giordano
Please, try this function and let me know if there are any problems:
Code: Select all
#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
EMG
Re: AscW() function
Posted: Thu Jun 13, 2019 7:37 am
by Natter
Latin's fine. However, this function returns incorrect Unicode Cyrillic characters
Re: AscW() function
Posted: Thu Jun 13, 2019 8:07 am
by Enrico Maria Giordano
Can you send me a sample showing the problem, please?
EMG
Re: AscW() function
Posted: Thu Jun 13, 2019 8:34 am
by nageswaragunupudi
Working correctly for me with this test:
Code: Select all
local n, c
n := 0xE100
c := HB_UTF8CHR( n )
? HB_UTF8ASC( HB_UTF8CHR( n ) ) == n // --> .T.
? HB_UTF8CHR( HB_UTF8ASC( c ) ) == c // --> .T.
Re: AscW() function
Posted: Thu Jun 13, 2019 9:15 am
by Natter
I didn't understand. There is a character with a code of 128 (1 byte) If you convert this character to Unicode it will consist of 2 bytes and its code will be 1040. How can I do this through the HB_UTF8ASC function() ?