gpt4 book ai didi

c++ - 处理带有特殊字符的 Hunspell 建议

转载 作者:行者123 更新时间:2023-11-28 03:34:50 26 4
gpt4 key购买 nike

我已经集成了 Hunspell在 Windows 7 上使用 Visual Studio 2010 的非托管 C++ 应用程序中。

我有适用于英语的拼写检查和建议,但现在我正试图让这些东西适用于西类牙语并遇到一些障碍。每当我收到有关西类牙语的建议时,带有重音字符的建议都无法正确转换为 std::wstring 对象。

这是从 Hunspell->suggest 方法返回的建议示例:

Hunspell->suggest(...) result

这是我用来将 std::string 转换为 std::wstring

的代码
std::wstring StringToWString(const std::string& str)
{
std::wstring convertedString;
int requiredSize = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, 0, 0);
if(requiredSize > 0)
{
std::vector<wchar_t> buffer(requiredSize);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &buffer[0], requiredSize);
convertedString.assign(buffer.begin(), buffer.end() - 1);
}

return convertedString;
}

在我运行完之后,我得到了这个,最后是时髦的角色。

After conversion to wstring

谁能帮我弄清楚这里的转换会发生什么?我猜测它与从 hunspell 返回的负字符有关,但不知道如何将其转换为 std::wstring 转换代码的内容。

最佳答案

看起来 Hunspell 的输出是代码页为 852 的 ASCII。使用 852 而不是 CP_UTF8 http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756(v=vs.85).aspx

或者配置 Hunspell 返回 UTF8。

关于c++ - 处理带有特殊字符的 Hunspell 建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11269586/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com