简体   繁体   English

CoreFoundation打印Unicode字符

[英]CoreFoundation printing Unicode characters

I have the current code and it does seem to work except for the fact CFShow doesn't translate the unicode UTF8 encoding of to é 我有当前代码,除了CFShow不会将\\ u00e9的Unicode UTF8编码转换为é之外,它似乎确实可以工作

#include <CoreFoundation/CoreFoundation.h>

int main()
{

    char *s = "This is a test of unicode support: fiancée\n";
    CFTypeRef cfs = CFStringCreateWithCString(NULL, s, kCFStringEncodingUTF8);
    CFShow(cfs);

}

Output is 输出是

This is a test of unicode support: fianc\u00e9e
                                        |____|
                                           > é doesn't output properly.

How do I instruct CFShow that it is unicode? 如何指示CFShow它是unicode? printf handles it fine when it is ac string. 当它是ac字符串时,printf可以很好地处理它。

CFShow() is only for debugging. CFShow()仅用于调试。 It's deliberately converting non-ASCII to escape codes in order to avoid ambiguity. 为了避免歧义,它故意将非ASCII转换为转义代码。 For example, "é" can be expressed in two ways: as U+00E9 LATIN SMALL LETTER E WITH ACUTE or as U+0065 LATIN SMALL LETTER E followed by U+0301 COMBINING ACUTE ACCENT. 例如,“é”可以用两种方式表示:U + 00E9带有小写字母的拉丁文小写字母E或U + 0065带有小写字母的拉丁文小写字母E,再加上U + 0301组合小写字母。 If CFShow() were to emit the UTF-8 sequence, your terminal would likely present it as "é" and you wouldn't be able to tell which variant was in the string. 如果CFShow()要发出UTF-8序列,则您的终端可能会将其显示为“é”,并且您将无法确定字符串中的哪个变体。 That would undermine the usefulness of CFShow() for debugging. 那会破坏CFShow()调试的有用性。

Why do you care what the output of CFShow() so long as it you understand what the content of the string is? 只要了解字符串的内容,为什么CFShow()关心CFShow()的输出?

It appears to me that CFShow knows that the string is Unicode, but doesn't know how to format Unicode for the console. 在我看来, CFShow知道该字符串是Unicode,但不知道如何为控制台设置Unicode格式。 I doubt that you can do anything but look for an alternative, perhaps NSLog . 我怀疑您除了寻找替代品(也许是NSLog ,还能做任何其他事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM