MultiByteToWideChar WINE vs Win32没有返回相同的结果!? [英] MultiByteToWideChar WINE vs Win32 not returning same result!?

查看:51
本文介绍了MultiByteToWideChar WINE vs Win32没有返回相同的结果!?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将utf8转换为utf16 / unicode,我希望在windows和linux下获得相同的结果。



注意:0xBF无效utf8字符。



c:

I am converting utf8 to utf16/unicode and I want to get the same result under windows and linux.

Note: "0xBF" is not valid utf8 character.

c:

char str[] = { 0xBF, 0 };
MultiByteToWideChar(CP_UTF8, 0, str, nLen8, pszUtf16, nLen16);





c#



c#

byte[] abCH = new byte[] { 0xBF };
string str = System.Text.Encoding.UTF8.GetString(abCH);
byte[] abCHUni = Encoding.Unicode.GetBytes(str);





在windows下,c和c#代码将返回:

0xBF转换为0xFD 0xFF。



在linux下(由WINE运行的同一个可执行文件):

0xBF未转换。



在Windows下(从WINE源调用MultiByteToWideChar)代码):

0xBF未转换。



Microsoft和WINE函数MultiByteToWideChar对于无效的utf8不会返回相同的结果字符。



有没有人有MultiByteToWideChar(来自微软)的源代码或者在windows / linux下为无效的utf8字符产生相同结果的代码?



问候,

Tomice



Under windows, c and c# code will return:
"0xBF" is converted to "0xFD 0xFF".

Under linux (same executable run by WINE):
"0xBF" is not converted.

Under windows (call to MultiByteToWideChar from WINE source code):
"0xBF" is not converted.

Microsoft and WINE function "MultiByteToWideChar" does not return the same result for invalid utf8 characters.

Does anyone have source code for "MultiByteToWideChar"(from Microsoft) or code that will produce the same result under windows / linux for invalid utf8 characters?

Regards,
Tomice

推荐答案

两种处理都是合规的。 Unicode规范允许发出错误信号,删除无效代码或用替换字符替换它(通常是U + FFFD REPLACEMENT CHARACTER)。



如果你需要相同的您可以尝试使用 MB_ERR_INVALID_CHARS 标志的行为。然后函数调用将失败。



MS代码不公开,不会帮助您。查看Wine源代码显示函数 wine_utf8_mbstowcs (参见 http://source.winehq.org/source/libs/wine/utf8.c [ ^ ])由 WideCharToMultiByte 调用,只是跳过无效代码。
Both handling is compliant. The Unicode specs allow signaling an error, removing the invalid code, or replacing it with a replacement character (usually the U+FFFD REPLACEMENT CHARACTER).

If you need identical behaviour you can try to use the MB_ERR_INVALID_CHARS flag. Then the function calls should fail.

The MS code is not public and won't help you. Having a look at the Wine sources shows that the function wine_utf8_mbstowcs (see http://source.winehq.org/source/libs/wine/utf8.c[^]) called by WideCharToMultiByte simply skips invalid codes.


这篇关于MultiByteToWideChar WINE vs Win32没有返回相同的结果!?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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