XString to char UTF8

asked Mar 13, 2019 in System Integration by g.costa
Hi EW,

in your tool/lib there is a function, named EwNewStringUtf8, that I can use to convert a UTF8 string to the "Object" XString.

Is ther also a function (or a way) to convert a XString in a UTF8 string (char array)?


Gianluca Costa

1 Answer

+1 vote
answered Mar 13, 2019 by Paul Banach
Best answer

Hello Gianluca,

the function to encode a UTF8 string from XString is actually not available. However, this enhancement is already waiting on our to-do list. For the moment you will need to implement the function by yourself. The following dummy code could help you (based on the description found here):

XChar*         src = <EmWi String>
unsigned char* dst = <buffer to store the encoded URF8>

for ( ; src && *src; src++ )
  XChar c = *src;

  if ( *src <= 0x007F )
    *dst++ = (unsigned char)c;
  else if ( *src <= 0x07FF )
    *dst++ = (unsigned char)( c >> 6 )   | 0xA0;
    *dst++ = (unsigned char)( c & 0x3F ) | 0x80;
  else if ( *src <= 0xFFFF )
    *dst++ = (unsigned char)( c >> 12 ) | 0xE0;
    *dst++ = (unsigned char)(( c >> 6  ) & 0x3F ) | 0x80;
    *dst++ = (unsigned char)( c & 0x3F ) | 0x80;

Best regards

Paul Banach

commented Mar 13, 2019 by g.costa
Hello Paul,

ok, thanks.

This means that XChar is in pure UNICODE (without encoding UTF8 or UTF16 or ....) and so with XChar I can manage all and only the UNICODE Plane 0. Is it right?

Best regards.

Gianluca Costa
commented Mar 13, 2019 by Paul Banach
Hello Gianluca,

yes. Embedded Wizards manages the strings and chars as code points from the range 0x0000 - 0xFFFF (UNICODE Plane 0). Code points above 0xFFFF are not supported.

Best regards

Paul banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint