"John Harrison" <
[email protected]> wrote in message
wael said:
"John Harrison" <
[email protected]> wrote in message
Do you mean that you want to convert locale specific strings
like
ASCII,
utf8, big5, etc into unicode UCS2 two byte entities, and then
store
them
in
a wchar_t?
Like this?
wchar_t ch = L'A';
char bytes[2];
bytes[0] = ch/256; // byte[0] == 0x00
bytes[1] = ch%256; // byte[1] == 0x41
Still not completely clear what you are trying to do.
john
thank you for help ,
let me be more clear:-
1- i receive text from ascii socket like this ( i will assume it is on
{0041 , 0628 , 0627 , 0042}
each 4 chars is UCS-2 encoded hex as defined in
http://www.unicode.org/charts/
00 prifx for english 41 char as defined in chart
http://www.unicode.org/charts/PDF/U0000.pdf
06 prifx for arabic 28 is char as defined in chart
http://www.unicode.org/charts/PDF/U0600.pdf
also i receive data for other languages like greek
i want convert incoming string to wchar_t and from wchar_t to send it
by socket
OK, try again, perhaps like this?
ascii_data is your string of unicode numbers seperated by commas and with a
leading { and trailing }. I.e. what you read from the socket. At the end
unicode_data is a wide string of Unicode characters, you can write that to
your other socket.
#include <algorithm>
#include <istream>
#include <sstream>
#include <string>
int main()
{
std::string ascii_data = "{0041 , 0628 , 0627 , 0042}";
// remove leading and trailing {}
ascii_data.erase(ascii_data.begin());
ascii_data.erase(ascii_data.end() - 1);
// replace commas with spaces
std::replace(ascii_data.begin(), ascii_data.end(), ',', ' ');
// use string as stream
std::istringstream str(ascii_data);
// read hex numbers from stream
std::wstring unicode_data;
unsigned char_value;
while (str >> std::hex >> char_value)
{
unicode_data.push_back(static_cast<wchar_t>(char_value));
}
}
john
Thank you for your help \
the code you send me is cool but for sorry it works for english only
look at this code:
//this what notepad do
BYTE aa[2];
//header for text notepad.exe it tells notepad.exe that file type is unicode
aa[0] = 0xFE;
aa[1] = 0xFF;
//end header
// my problem is here how to encode 06 28 into wchar
// or how notepad read this file
//this codes is valid and if you have installed arabic language in win2000 or nt
//you will see it fine
//hex vaue is not like english
// by mean hex('A') = 41 is not the same for other languages
//by mean hex '\x28' is not the same if i get hex(ascii code of its char)
//and this is the real problem
BYTE bb[4]; // 4 bytes = 2 bytes unicode
bb[0] = '\x06'; //unicode hex encoding prefix
bb[1] = '\x28'; //unicode hex encoding
bb[2] = '\x06'; //unicode hex encoding prefix
bb[3] = '\x27'; //unicode hex encoding
FILE *stream;
stream = fopen( "c:\\fprintf.txt", "w" );
fwrite( aa, sizeof(BYTE), 2, stream ); //write header
fwrite( bb, sizeof(BYTE), 4, stream ); //write data
fcloseall();//close stream
thank you for take time read this
wael ahmed