 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
wael Guest
|
Posted: Thu Aug 14, 2003 6:41 pm Post subject: UCS-2 |
|
|
Hello,
i want return the encoded string for unicode char
by example
this code
wchar_t xx = 'A';
'A' should be retrned 00 65 as ucs-2 encoded charcter
(please check
http://www.unicode.org/charts/
i hope you will understand what i mean ,,
thank you for take time read this
wael ahmed
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ron Natalie Guest
|
Posted: Fri Aug 15, 2003 2:16 am Post subject: Re: UCS-2 |
|
|
"wael" <twaeltt (AT) hotmail (DOT) com> wrote
| Quote: | Hello,
i want return the encoded string for unicode char
by example
this code
wchar_t xx = 'A';
'A' should be retrned 00 65 as ucs-2 encoded charcter
(please check
http://www.unicode.org/charts/
i hope you will understand what i mean ,,
|
Well assuming that wchar_t is, in fact a 16 bit unicode encoded character (non-portable
assumption):
#include <iostream>
using namespace std;
int main() {
wchar_t wc = L'A';
cout << hex << ((wc >> &0xFF) << " " << (wc & 0xFF) << "n";
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Gianni Mariani Guest
|
Posted: Sat Aug 16, 2003 3:50 pm Post subject: Re: UCS-2 |
|
|
Ron Natalie wrote:
| Quote: | "wael" <twaeltt (AT) hotmail (DOT) com> wrote
Hello,
i want return the encoded string for unicode char
by example
this code
wchar_t xx = 'A';
'A' should be retrned 00 65 as ucs-2 encoded charcter
(please check
http://www.unicode.org/charts/
i hope you will understand what i mean ,,
Well assuming that wchar_t is, in fact a 16 bit unicode encoded character (non-portable
assumption):
#include <iostream
using namespace std;
int main() {
wchar_t wc = L'A';
cout << hex << ((wc >> &0xFF) << " " << (wc & 0xFF) << "n";
}
|
BTW - UCS-2 is more or less dead. UTF-16 replaces it. You need to deal
with surrogate pairs to print the correct codepoint value for unicode.
Now this is WAY non portable because some implementations of wchar_t are
UCS-4 and some are UTF-16.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Andy Heninger Guest
|
Posted: Mon Aug 25, 2003 9:13 am Post subject: Re: UCS-2 |
|
|
"Gianni Mariani" <gi2nospam (AT) mariani (DOT) ws> wrote
| Quote: | Ron Natalie wrote:
"wael" <twaeltt (AT) hotmail (DOT) com> wrote
wchar_t wc = L'A';
cout << hex << ((wc >> &0xFF) << " " << (wc & 0xFF) << "n";
BTW - UCS-2 is more or less dead. UTF-16 replaces it. You need to deal
with surrogate pairs to print the correct codepoint value for unicode.
Now this is WAY non portable because some implementations of wchar_t are
UCS-4 and some are UTF-16.
Even worse, there are still compilers around where wchar_t is not based on |
Unicode at all. If portability really matters, the only way to get Unicode
character constants is with numeric constants. Ugh.
-- Andy Heninger
[email]heninger (AT) us (DOT) ibm.com[/email]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|