Re: Xcode-users Digest, Vol 7, Issue 153
Re: Xcode-users Digest, Vol 7, Issue 153
- Subject: Re: Xcode-users Digest, Vol 7, Issue 153
- From: "Paul Sanders" <email@hidden>
- Date: Wed, 14 Apr 2010 00:04:48 +0100
> Just because it's wider than 8 bits doesn't mean that it can ignore
the locale. You are assuming that the UTF's and UCS's are the only encodings
that are wider than 8-bits. There is nothing stopping wchar_t from representing
GB18030.
In that case, there should be a 'wchar_t transparent' locale,
'cos that's what the situation demands. In any case,
GB18030 appears to be yet another multibyte character encoding so I don't
think your comment applies. If one wants to convert a wide string to
_any_ multibyte character set, one can call sprintf (char_buf, "%ls",
my_wide_string), and to do the opposite, call swprintf (wchar_t_buf, L"%s",
my_multibyte_string), setting the desired locale in both cases. swprintf
(wchar_t_buf, L"%ls", my_wide_string) can therefore afford to be wchar_t
transparent.
> If the goal is to re-use the TCHAR-based code on the
Mac, just define TCHAR as a no op, and use plain char. The compilers on the Mac
support UTF-8 string literals. That is, the following code is fine on the Mac
and works as expected: ...
That doesn't work if, as I do, you have existing code that expects to
iterate through or index into TCHAR *'s. The whole point here is to
be able to re-use such code. Trivial example:
TCHAR *s = ...;
if (s [0] = 'p' && s [1] = 'a' && s [2]
== 'u' and s [3] == 'l')
printf ("Please stop making so many
irritating and irrelevant posts, Mr Sanders");
This won't work if s is using a multi-byte encoding such as UTF-8.
I think we have done this one to death now, Clark. The biggest sin
for me is the complete lack of any discussion of these issues in the POSIX
standard or OS X man pages. As things stand, it's a sand-trap for the
unwary as at least two of us have already found out, but that doesn't mean
that wchar_t is unusuable. Far from it. It's working fine for me,
using the rather nice 'printf family' source code I originally posted a
link to.
Just to come back to what Jens said, a way to specify UTF-16 string
literals in gcc would be extremely welcome. It would allow me to halve the
size of the string variables in my code, for example. It would also
provide useful cross-platform support for us Windows guys. Or should that
be fall-guys? :)
Paul Sanders.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden