我终于为64位构建了我的库,现在在Mac,C++ 64位上从UTF-32LE到UTF-16LE的对话失败了。
在执行步骤之前,我的源是正确的字符串,执行iconv步骤将清除源和源大小。
iconv_t theHandle = NULL;
std::wstring source(L"My Source string to convert!");
size_t theSourceLength = source.length();
wchar_t *theSourceStart = (wchar_t*)source.c_str();
size_t sourceByteSize = sizeof(wchar_t)*theSourceLength;
UniChar* destination = new UniChar[ theSourceLength +2];
size_t destinationByteSize = sizeof(UniChar)*theSourceLength;
static const char *destinationEncoding = "UTF-16LE";
static const char *sourceEncoding = "UTF-32LE";
theHandle = iconv_open( destinationEncoding, sourceEncoding );
std::cout << "Conversion error: " << errno << std::endl;
if (errno == EINVAL)
std::cout << "EINVAL" << std::endl;
size_t convertedSize = iconv( theHandle, (char**)&theSourceStart, &sourceByteSize, (char**)&destination, &destinationByteSize );
std::cout << "Conversion error: " << errno << std::endl;
if (errno == E2BIG)
std::cout << "E2BIG" << std::endl;
if (errno == EILSEQ)
std::cout << "EILSEQ" << std::endl;
if (errno == EINVAL)
std::cout << "EINVAL" << std::endl;当我在调试器的图标行停止时,"theSourceStart“显示为"My Source string to convert!”convertedSize == 0和theSourceStart == L"",以及sourceByteSize == 0。
发布于 2018-01-08 23:48:02
我错了,它像预期的那样工作。我唯一遗漏的一件事,因为我在调试方面太深入了,缓冲区指针实际上是由iconv操作符更改的,这就是为什么我的源字符串似乎是空的。但是,如果我保留原始指针,则目标中的值被正确填充,并且源保持不变。所以我的应用程序可以工作了。
https://stackoverflow.com/questions/48150198
复制相似问题