XMLString :: transcode无法在Linux中转换UNICODE char [英] XMLString::transcode not able to convert UNICODE char in Linux
问题描述
有一个字符串Ë = D5 +!?!,当它存储在char *变量中时,它会被转换为Ã = D5 +!? !。我猜这是由于字节大小。
Ë的ASCII值是203(UNICODE字符)
const XMLCh * pXValue =Ë = D5 +!?!;
char * pValue = XMLString :: transcode(pXValue);
调用函数 XMLString :: transcode(Xerces Library函数)后,pValue包含Ã= D5 + !?!错误的字符串。
注意:在Windows中它工作正常但在Linux中会产生问题。
语言:VC ++
平台:Windows和Linux
框架:Visual Studio 2012
There is a string "Ë=D5+"!?!", when it is stored in char* variable it is converted to "Ã=D5+"!?!". I guess this is due to byte size.
ASCII value of Ë is 203 (UNICODE character)
const XMLCh* pXValue = "Ë=D5+"!?!";
char* pValue = XMLString::transcode( pXValue );
After calling of function XMLString::transcode(Xerces Library function), pValue contain "Ã=D5+"!?!" string which is wrong.
Note : In Windows it is working fine but in Linux it creates problem.
Language : VC++
Platform : Windows and Linux
Framework : Visual Studio 2012
推荐答案
这看起来像源文件编码问题。你的.cpp文件是用UTF-8编码的吗?您可以在GCC命令行上使用
This looks like a source file encoding issue. Is your .cpp file encoded in UTF-8? You can use the
-finput-charset=UTF-8
来指定源文件的编码。
感谢Vaclav Zeman的回复,我按照你的建议尝试但是没有解决我的问题。
XMLCh在Window上代表2字节,在Linux上代表这个值(Ë= D5 +!?!)需要4个字节的表示。
所以我创建了一个将4个字节转换为2个字节的函数,它起作用了。
Thanks Vaclav Zeman for reply and I tried as you suggested but that didn't resolve my problem.
The XMLCh represent 2 byte on Window and as well on Linux but this value( "Ë=D5+"!?!" ) require 4 byte representation.
So I create a function which convert 4 byte to 2 byte and it worked.
这篇关于XMLString :: transcode无法在Linux中转换UNICODE char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!