首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从UTF-32LE到UTF-16LE的"iconv“转换

从UTF-32LE到UTF-16LE的"iconv“转换
EN

Stack Overflow用户
提问于 2018-01-08 20:21:05
回答 1查看 261关注 0票数 0

我终于为64位构建了我的库,现在在Mac,C++ 64位上从UTF-32LE到UTF-16LE的对话失败了。

在执行步骤之前,我的源是正确的字符串,执行iconv步骤将清除源和源大小。

代码语言:javascript
复制
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。

EN

回答 1

Stack Overflow用户

发布于 2018-01-08 23:48:02

我错了,它像预期的那样工作。我唯一遗漏的一件事,因为我在调试方面太深入了,缓冲区指针实际上是由iconv操作符更改的,这就是为什么我的源字符串似乎是空的。但是,如果我保留原始指针,则目标中的值被正确填充,并且源保持不变。所以我的应用程序可以工作了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48150198

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档