从嵌入式应用程序的std :: string切换到std :: wstring? [英] Switching from std::string to std::wstring for embedded applications?

查看:255
本文介绍了从嵌入式应用程序的std :: string切换到std :: wstring?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到现在,我一直在嵌入式系统(路由器,交换机,电话机等)的C ++应用程序中使用std :: string。



对于下一个项目,我正在考虑从std :: string切换到std :: wstring进行Unicode支持。例如,这将允许最终用户在命令行界面(CLI)中使用汉字。



我应该期望什么并发症/头痛/惊喜?什么,例如,如果我使用仍然使用std :: string的第三方库?



由于支持国际字符串不是强大的要求我所工作的嵌入式系统的类型,只有当它不会引起严重的头痛时才会这样做。

解决方案

请注意,许多通信协议需要8位字符(或7位字符或其他品种),因此您经常需要在内部wchar_t / wstring数据和外部编码之间进行转换。



当您需要具有Unicode字符的8位表示时,UTF-8编码非常有用。 (请参阅如何编写安全的代码对于UTF-8?了解更多信息)但请注意,您可能需要支持其他编码。



越来越多的第三方库支持Unicode,但还是有很多没有。



我真的不能告诉你是否值得头痛。这取决于你的要求。如果你从头开始,那么从std :: wstring开始就比从std :: string转换成std :: wstring更容易了。


Up until now I have been using std::string in my C++ applications for embedded system (routers, switches, telco gear, etc.).

For the next project, I am considering to switch from std::string to std::wstring for Unicode support. This would, for example, allow end-users to use Chinese characters in the command line interface (CLI).

What complications / headaches / surprises should I expect? What, for example, if I use a third-party library which still uses std::string?

Since support for international strings isn't that strong of a requirement for the type of embedded systems that I work on, I would only do it if it isn't going to cause major headaches.

解决方案

Note that many communications protocols require 8-bit characters (or 7-bit characters, or other varieties), so you will often need to translate between your internal wchar_t/wstring data and external encodings.

UTF-8 encoding is useful when you need to have an 8-bit representation of Unicode characters. (See How Do You Write Code That Is Safe for UTF-8? for some more info.) But note that you may need to support other encodings.

More and more third-party libraries are supporting Unicode, but there are still plenty that don't.

I can't really tell you whether it is worth the headaches. It depends on what your requirements are. If you are starting from scratch, then it will be easier to start with std::wstring than converting from std::string to std::wstring later.

这篇关于从嵌入式应用程序的std :: string切换到std :: wstring?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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