// CodeTransfer.cpp: implementation of the CCodeTransfer class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include <time.h>
#include <stdio.h>
#include "CodeTransfer.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCodeTransfer::CCodeTransfer()
{

}

CCodeTransfer::~CCodeTransfer()
{

}

int CCodeTransfer::utf8tomultibyte(const char *szUtf8, char *szmutibyte, int outbuflen)
{
	int iRet;
	int srclen = strlen(szUtf8) + 1;
	int unilen = (srclen << 2);
	WCHAR *szUniCode = new WCHAR[unilen];
	iRet = MultiByteToWideChar(CP_UTF8, 0, szUtf8, srclen, szUniCode, unilen);
	iRet = WideCharToMultiByte(CP_ACP, NULL, szUniCode, iRet, szmutibyte, outbuflen, NULL, NULL);
	delete szUniCode;
	return iRet;
}

int CCodeTransfer::multibytetoutf8(const char *szmutibyte, char *szUtf8, int outbuflen)
{
	int iRet;
	int srclen = strlen(szmutibyte) + 1;
	int unilen = (srclen << 2);
	WCHAR *szUniCode = new WCHAR[unilen];
	iRet = MultiByteToWideChar(CP_ACP, MB_COMPOSITE, szmutibyte, srclen, szUniCode, unilen);
	iRet = WideCharToMultiByte(CP_UTF8, 0, szUniCode, iRet, szUtf8, outbuflen, NULL, NULL);
	szUtf8[outbuflen - 1] = 0;
	delete szUniCode;
	return iRet;
}
