AscW() function

AscW() function

Postby Natter » Tue Jun 11, 2019 10:57 am

Hi, all !

VBA (Excel) has an AscW() function. It is used to obtain the Unicode character code. How do I do this on FW ?
Natter
 
Posts: 1207
Joined: Mon May 14, 2007 9:49 am

Re: AscW() function

Postby nageswaragunupudi » Tue Jun 11, 2019 1:20 pm

Please try
Code: Select all  Expand view

HB_UTF8CHR( nChar )
 

Maybe that is what you are looking for.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: AscW() function

Postby AntoninoP » Tue Jun 11, 2019 1:31 pm

AscW return the unicode value from character or string. I think the Harbour version is HB_UTF8ASC:
Code: Select all  Expand view
HB_UTF8ASC( <cUtf8> ) -> <nUnicode>

HB_UTF8CHR is:
Code: Select all  Expand view
HB_UTF8CHR( <nUniVal> ) -> <cUtf8Char>
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: AscW() function

Postby nageswaragunupudi » Tue Jun 11, 2019 1:34 pm

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: AscW() function

Postby Natter » Tue Jun 11, 2019 1:42 pm

Yes, the HB_UTF8Asc() function suits me, but it is not available for FWH18.06
Natter
 
Posts: 1207
Joined: Mon May 14, 2007 9:49 am

Re: AscW() function

Postby nageswaragunupudi » Tue Jun 11, 2019 1:44 pm

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: AscW() function

Postby Natter » Tue Jun 11, 2019 2:53 pm

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

Re: AscW() function

Postby Enrico Maria Giordano » Tue Jun 11, 2019 3:09 pm

I confirm: there is no hb_utf8asc() function in xHarbour. I can try to add it to xHarbour, if you really need it.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: AscW() function

Postby Natter » Tue Jun 11, 2019 4:48 pm

Yes, I do. I will be very grateful to you
Natter
 
Posts: 1207
Joined: Mon May 14, 2007 9:49 am

Re: AscW() function

Postby Enrico Maria Giordano » Tue Jun 11, 2019 5:18 pm

Ok, I'll see what I can do...

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: AscW() function

Postby Enrico Maria Giordano » Tue Jun 11, 2019 9:15 pm

Please, try this function and let me know if there are any problems:

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: AscW() function

Postby Natter » Thu Jun 13, 2019 7:37 am

Latin's fine. However, this function returns incorrect Unicode Cyrillic characters
Natter
 
Posts: 1207
Joined: Mon May 14, 2007 9:49 am

Re: AscW() function

Postby Enrico Maria Giordano » Thu Jun 13, 2019 8:07 am

Can you send me a sample showing the problem, please?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: AscW() function

Postby nageswaragunupudi » Thu Jun 13, 2019 8:34 am

Working correctly for me with this test:
Code: Select all  Expand view

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

Re: AscW() function

Postby Natter » Thu Jun 13, 2019 9:15 am

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() ?
Natter
 
Posts: 1207
Joined: Mon May 14, 2007 9:49 am

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 35 guests