Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Below is a sample code snippet for using ICharsetConv for converting UTF-8 to Shift_JIS(S-JIS) & back.
the same code may be used to convert between any of the supported encodings. 
The only difference would be to get an appropriate handler for the conversion.
The supported encoding are defined in AEESJISConv.bid.
format for getting a handler using IRegistery is to_encoding>from_encoding
For eg: IREGISTRY_GetHandler(pReg, AEEIID_ICharsetConv, "Shift_JIS>UTF-8"); - for converting UTF-8 to S_JIS.
 
 
 
#include "AEEICharsetConv.h"
#include "AEERegistry.h"

void testUnicode(myApp *pMe)
{
  byte*buff;
  int size;
  AECHAR szBuf[20];
  AEECLSID cls;
  ICharsetConv *pCharConv;
  int nErr;
  IRegistry *pReg;
  int pnNum = 0;
  int nDstSize = 100;
  byte *toDisplay;
  byte *toSJIS;

  byte *ppDstBuf = (byte*)MALLOC(100);
  byte *ppSrcBuf = (byte*)MALLOC(100);

  toDisplay = ppDstBuf;
  toSJIS = ppSrcBuf;


//Copying UTF-8 chars from a File 2.html
//Remove or replace with the UTF-8 bytes reader method
copyFileToBuff(pMe, "2.htm", &buff, &size);

MEMCPY(ppSrcBuf, buff, size);


if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_REGISTRY, (void**)&pReg) != SUCCESS) {
          return;


//getting class for converting UTF-8 to S-JIS
cls = IREGISTRY_GetHandler(pReg, AEEIID_ICharsetConv, "Shift_JIS>UTF-8");

if(ISHELL_CreateInstance(pMe->a.m_pIShell, cls, (void**)&pCharConv) != SUCCESS) {
	return;


nErr = ICharsetConv_Initialize(pCharConv, "UTF-8", "Shift_JIS", 0x20);
if(AEE_SUCCESS != nErr) {
     return;



nErr = ICharsetConv_CharsetConvert(pCharConv, &ppSrcBuf,  &size, (unsigned char**)&ppDstBuf,  &nDstSize, &pnNum);

RELEASEIF(pCharConv);

//Now converting back the SJIS returned ppDstBuf(or the stored pointer toDisplay) to UTF-8
//getting class of converting S-JIS to UTF-8
cls = IREGISTRY_GetHandler(pReg, AEEIID_ICharsetConv, "UTF-8>Shift_JIS");

if(ISHELL_CreateInstance(pMe->a.m_pIShell, cls, (void**)&pCharConv) != SUCCESS) {
	return;


nErr = ICharsetConv_Initialize(pCharConv, "Shift_JIS", "UTF-8", 0x20);
if(AEE_SUCCESS != nErr) {
      return;


size = 100 - nDstSize;
nDstSize = 100;
nErr = ICharsetConv_CharsetConvert(pCharConv, &toDisplay,  &size, (unsigned char**)&ppSrcBuf,  &nDstSize, &pnNum);

IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_BOLD, (AECHAR*)toDisplay, -1, 0, 0, 0, IDF_ALIGN_CENTER|IDF_ALIGN_MIDDLE);
IDISPLAY_Update(pMe->a.m_pIDisplay);

//MALLOC buffers should be stored & released
RELEASEIF(pReg);
RELEASEIF(pCharConv);