Idea: The input string must end with ' + ' and if the input string does not end with '/', set it manually, otherwise the conversion will have an error.
unsigned int encodeutil::ansitoucs2 (char* pansi, wchar_t*& pUcs2)
{
//Pre-conversion to get the size of the required space
int wcsLen =:: MultiByteToWideChar (CP_ACP, NULL, Pansi, strlen (Pansi), NULL, 0);
//Allocate space to make a space for ' MultiByteToWideChar ', it will not give ' \ ' space
PUCS2 = new Wchar_t[wcslen + 1];
//Conversion
:: MultiByteToWideChar (CP_ACP, NULL, Pansi, strlen (Pansi), PUCS2, wcsLen);
//Last Plus ' /'
Pucs2[wcslen] = ' + ';
return wcsLen;
}
unsigned int encodeutil::ucs2toansi (wchar_t* pUcs2, char*& pansi)
{
//Pre-conversion, to get the size of the required space, this time with the function and the above name opposite
int ansilen =:: WideCharToMultiByte (CP_ACP, NULL, PUCS2, Wcslen (PUCS2), NULL, 0, NULL, NULL);
///Ibid., allocate space to make a space for '/ '
Pansi = new Char[ansilen + 1];
//Conversion
the//unicode version corresponds to the strlen is Wcslen
:: WideCharToMultiByte (CP_ACP, NULL, PUCS2, Wcslen (PUCS2), Pansi, ansilen, NULL, NULL);
//Last Plus ' /'
Pansi[ansilen] = ' + ';
return ansilen;
}
unsigned int Encodeutil::ucs2toutf8 (wchar_t* pUcs2, char*& PUtf8)
{
//Pre-conversion, to get the size of the required space, this time with the function and the above name opposite
int u8len =:: WideCharToMultiByte (Cp_utf8, NULL, PUCS2, Wcslen (PUCS2), NULL, 0, NULL, NULL);
///Ibid., allocate space to make a space for '/ '
Although//utf8 is a Unicode form of compression, it is also a multibyte string, so it can be saved as Char
PUtf8 = new Char[u8len + 1];
//Conversion
the//unicode version corresponds to the strlen is Wcslen
:: WideCharToMultiByte (Cp_utf8, NULL, PUCS2, Wcslen (PUCS2), PUtf8, u8len, NULL, NULL);
//Last Plus ' /'
Putf8[u8len] = ' + ';
return u8len;
}
unsigned int encodeutil::utf8toucs2 (char* PUtf8, wchar_t*& pUcs2)
{
//Pre-conversion to get the size of the required space
int wcsLen =:: MultiByteToWideChar (Cp_utf8, NULL, PUtf8, strlen (PUTF8), NULL, 0);
//Allocate space to make a space for ' MultiByteToWideChar ', it will not give ' \ ' space
PUCS2 = new Wchar_t[wcslen + 1];
//Conversion
:: MultiByteToWideChar (Cp_utf8, NULL, PUtf8, strlen (PUtf8), PUCS2, wcsLen);
//Last Plus ' /'
Pucs2[wcslen] = ' + ';
return wcsLen;
}
unsigned int Encodeutil::ansitoutf8 (char* pansi, char*& PUtf8)
{
wchar_t* PUCS2 = NULL;
ANSITOUCS2 (Pansi, PUCS2);
unsigned int len = Ucs2toutf8 (PUCS2, PUtf8);
Delete[] PUCS2;
return Len;
}
Character encoding conversion under Windows