C语言编程:如何为统一code程序? [英] C programming: How to program for Unicode?

查看:134
本文介绍了C语言编程:如何为统一code程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

做严格的统一code编程需要什么prerequisites?

What prerequisites are needed to do strict Unicode programming?

类型的任何位置,其功能需要使用,可以处理所述wint_t wchar_t的

Does this imply that my code should not use char types anywhere and that functions need to be used that can deal with wint_t and wchar_t?

什么是多字节字符序列在此方案中所扮演的角色?

And what is the role played by multibyte character sequences in this scenario?

推荐答案

请注意,这不是关于严格的UNI code程序设计本身,而是一定的实践经验。

Note that this is not about "strict unicode programming" per se, but some practical experience.

我们所做的在我的公司是创建一个围绕IBM的ICU库包装库。该包装库有UTF-8的界面和转换为UTF-16时,需要调用ICU。在我们的例子中,我们并没有过于担心性能命中。当性能是一个问题,我们也提供UTF-16接口(用我们自己的数据类型)。

What we did at my company was to create a wrapper library around IBM's ICU library. The wrapper library has a UTF-8 interface and converts to UTF-16 when it is necessary to call ICU. In our case, we did not worry too much about performance hits. When performance was an issue, we also supplied UTF-16 interfaces (using our own datatype).

应用程序可以在很大程度上仍然原样(使用CHAR),虽然在某些情况下,他们需要知道的一些问题。例如,代替函数strncpy(),我们使用这避免切断的UTF-8序列的包装。在我们的例子,这是足够了,但我们也可以考虑结合字符检查。我们也有包装计数codepoints的数量,字形的数量,等等。

Applications could remain largely as-is (using char), although in some cases they need to be aware of certain issues. For instance, instead of strncpy() we use a wrapper which avoids cutting off UTF-8 sequences. In our case, this is sufficient, but one could also consider checks for combining characters. We also have wrappers for counting the number of codepoints, the number of graphemes, etc.

在与其他系统的接口,我们有时需要做自定义字符组成,所以你可能需要一定的灵活性存在(取决于您的应用程序)。

When interfacing with other systems, we sometimes need to do custom character composition, so you may need some flexibility there (depending on your application).

我们不使用wchar_t的。使用ICU避免在便携意外的问题(而不是其他意外问题,当然: - )。

We do not use wchar_t. Using ICU avoids unexpected issues in portability (but not other unexpected issues, of course :-).

这篇关于C语言编程:如何为统一code程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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