---
title: "对字符编码问题，这里给出ice的策略"
author: "monkeycn"
date: "2011-10-31T13:17:57Z"
tags: []
categories: ["编程语言"]
slug: "ice"
draft: false
lastmod: "2011-10-31T13:17:57Z"
id: 1224595
url: "https://monkeycn.iteye.com/blog/1224595"
---

对字符编码问题，这里给出ice的策略：
#1 Narrow strings (that is, strings mapped to std::string) are presented to
the application in UTF-8 encoding and, similarly, the application is expected
to provide narrow strings in UTF-8 encoding to the Ice run time for transmission.

首先以8位为一个字节的字符格式，例如ascii,gbk，等，就是能在std::string下正常显示的，ice要求用户自己提供从他们自己的平台语言转换为utf8的方法

当然ascii天生兼容utf8，这个不用转.

比如我们的情况，中文版win，用的gbk，那么咱们用ice的时候要提供一个方法，把字符从gbk转换为utf8.



#2 Wide strings (that is, strings mapped to std::wstring) are automatically
encoded as Unicode by the Ice run time as appropriate for the platform. For
example, for Windows, the Ice run time converts between UTF-8 and UTF-16
in little-endian representation whereas, for Linux, the Ice run time converts
between UTF-8 and UTF-32 in the endian-ness appropriate for the host CPU.