我已经集成了 Hunspell在 Windows 7 上使用 Visual Studio 2010 的非托管 C++ 应用程序中。
我有适用于英语的拼写检查和建议,但现在我正试图让这些东西适用于西类牙语并遇到一些障碍。每当我收到有关西类牙语的建议时,带有重音字符的建议都无法正确转换为 std::wstring
对象。
这是从 Hunspell->suggest
方法返回的建议示例:
这是我用来将 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;
}
在我运行完之后,我得到了这个,最后是时髦的角色。
谁能帮我弄清楚这里的转换会发生什么?我猜测它与从 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/