Re: How to display Japanese in debug console?
Re: How to display Japanese in debug console?
- Subject: Re: How to display Japanese in debug console?
- From: Norio Ota <email@hidden>
- Date: Sun, 25 Jun 2006 22:56:31 +0900
How kind of you! Thank you, Damien. I'll try to do that.
norio
On 2006年 6月 25日 , at 09:15 PM, Damien Bobillot wrote:
Norio Ota wrote :
Thanks for your kind mail.
As you might have got what I really wanted, I'd like to read ASCII
characters which is Japanese from a file and display it in Japanese
on the console. The file is not UTF8. And I don't think it's a good
idea for me to convert the file from ASCII to UTF8, because it's not
just text file, but complicate-formatted file.
My app needs to extract a portion of the file and display it in
Japanese on the console.
When I read your mail, I thought NSLog might help me out. However,
unfortunately I use Carbon, so I have a compile error with NSLog.
You need to add the Cocoa framework to the "link with libraries &
frameworks" build phase (you may get an warning saying that NSLog is
not declared, but it's not important).
On 2006年 6月 25日 , at 06:54 PM, Damien Bobillot wrote:
Norio Ota wrote :
Would you tell me how to display Japanese on the debug console
window?
// the content in the quotation mark is actually Japanese.
fprintf ( stderr, "Nihongo string here" ); // it works.
It works because your source file is encoded in UTF8, and the
console window expects UTF8 characters.
// the following codes don't work. The string in the quotation is
also Japanese.
char * c_str = "Nihongo".
fprintf ( stderr, "%s\n", c_str ); // not work.
I think this code is not in the same file as the previous one. If
the file is encoded with UTF8, it should work.
CFStringRef cfRef = CFStringCreateWithCString (NULL, c_str,
CFStringGetSystemEncoding());
There's an error here : never use CFStringGetSystemEncoding() in
this situation ! Your string is hard coded in the binary, so it has
a precise encoding. The user may change the system default encoding,
so it will be a chance that he choose the good one.
The good way to do that is to also hardcode the encoding. If your
source file is encoded with UTF8, use kCFStringEncodingUTF8.
CFShow (cfRef); // not work
CFShow convert all non-ascii characters to "\uXXXX", so it's not a
good choice for such tests. You may use the Cocoa NSLog instead (and
link against the Cocoa framework).
CFRelease ( cfRef);
Here's a test I ran successfully (with greek characters encoded in
UTF8) :
fprintf(stderr, "λαμβδα\n");
char * c_str = "λαμβδα bis";
fprintf ( stderr, "%s\n", c_str );
CFStringRef cfRef = CFStringCreateWithCString(NULL, c_str,
kCFStringEncodingUTF8);
NSLog(cfRef);
CFRelease(cfRef);
--
Damien Bobillot
--
Damien Bobillot
_______________________________________________
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