1

我有当前的代码,它似乎确实有效,除了 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);

}

输出是

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

我如何指示 CFShow 它是 unicode?当它是交流字符串时,printf 可以很好地处理它。

4

2 回答 2

5

CFShow() is only for debugging. It's deliberately converting non-ASCII to escape codes in order to avoid ambiguity. 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. 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. That would undermine the usefulness of CFShow() for debugging.

Why do you care what the output of CFShow() so long as it you understand what the content of the string is?

于 2013-09-07T02:08:12.280 回答
1

在我看来,CFShow知道字符串是 Unicode,但不知道如何为控制台格式化 Unicode。我怀疑除了寻找替代方案之外,您可以做任何事情,也许NSLog

于 2013-09-07T01:57:13.390 回答