印刷的CoreFoundation统一code字 [英] CoreFoundation printing Unicode characters

查看:141
本文介绍了印刷的CoreFoundation统一code字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前的code和它似乎除了事实CFShow不翻译的 \\ u00e9 到E

I have the current code and it does seem to work except for the fact CFShow doesn't translate the unicode UTF8 encoding of \u00e9 to é

#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,它是单向code? printf的处理它很好,当它是一个C字符串。

How do I instruct CFShow that it is unicode? printf handles it fine when it is a c string.

推荐答案

CFShow()仅用于调试。它故意将非ASCII为了避免歧义逃避codeS。例如,E可前$ P $有两种方式pssed:如急性U + 00E9拉丁小写字母E或作为U + 0065拉丁小字母E其次是U + 0301组合重音符。如果 CFShow()是发出的UTF-8序列,你的终端将可能present它作为E和你将无法判断哪个变种是的字符串中。这将破坏 CFShow()的有效性进行调试。

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.

为什么你关心的输出 CFShow()只要你了解字符串的内容是什么?

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

这篇关于印刷的CoreFoundation统一code字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆