AscW() function

Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

AscW() function

Post 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 ?
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: AscW() function

Post by nageswaragunupudi »

Please try

Code: Select all

HB_UTF8CHR( nChar )
 
Maybe that is what you are looking for.
Regards

G. N. Rao.
Hyderabad, India
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: AscW() function

Post 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>
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: AscW() function

Post by nageswaragunupudi »

Yes, Mr. Antonio
And thanks for the correction.
Regards

G. N. Rao.
Hyderabad, India
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

Re: AscW() function

Post by Natter »

Yes, the HB_UTF8Asc() function suits me, but it is not available for FWH18.06
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: AscW() function

Post by nageswaragunupudi »

This is not FWH function.
This is a Harbour function available both in Harbour and xHarbour.
Regards

G. N. Rao.
Hyderabad, India
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

Re: AscW() function

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: AscW() function

Post 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
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

Re: AscW() function

Post by Natter »

Yes, I do. I will be very grateful to you
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: AscW() function

Post 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
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

Re: AscW() function

Post by Natter »

Latin's fine. However, this function returns incorrect Unicode Cyrillic characters
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: AscW() function

Post 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.
 
Regards

G. N. Rao.
Hyderabad, India
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

Re: AscW() function

Post 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() ?
Post Reply