AscW() function
AscW() function
Hi, all !
VBA (Excel) has an AscW() function. It is used to obtain the Unicode character code. How do I do this on FW ?
VBA (Excel) has an AscW() function. It is used to obtain the Unicode character code. How do I do this on FW ?
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: AscW() function
Please try
Maybe that is what you are looking for.
Code: Select all
HB_UTF8CHR( nChar )
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: AscW() function
AscW return the unicode value from character or string. I think the Harbour version is HB_UTF8ASC:
HB_UTF8CHR is:
Code: Select all
HB_UTF8ASC( <cUtf8> ) -> <nUnicode>
Code: Select all
HB_UTF8CHR( <nUniVal> ) -> <cUtf8Char>
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: AscW() function
Yes, Mr. Antonio
And thanks for the correction.
And thanks for the correction.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: AscW() function
Yes, the HB_UTF8Asc() function suits me, but it is not available for FWH18.06
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: AscW() function
This is not FWH function.
This is a Harbour function available both in Harbour and xHarbour.
This is a Harbour function available both in Harbour and xHarbour.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: AscW() function
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
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: AscW() function
I confirm: there is no hb_utf8asc() function in xHarbour. I can try to add it to xHarbour, if you really need it.
EMG
EMG
Re: AscW() function
Yes, I do. I will be very grateful to you
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: AscW() function
Please, try this function and let me know if there are any problems:
EMG
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
Re: AscW() function
Latin's fine. However, this function returns incorrect Unicode Cyrillic characters
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: AscW() function
Can you send me a sample showing the problem, please?
EMG
EMG
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: AscW() function
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.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: AscW() function
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() ?