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

标签 c++ ascii hunspell

我已经集成了 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/

相关文章:

c++ - 如何在 C++ 中为 copy_if 等定义 "unary predicate"?

c++ - 使用平假名将 std::wstring 转换为 QString

c++ - 在使用 unique_ptr 的函数调用中使用大括号初始化的自动类型推导失败

ruby-on-rails - "Ascii85":String

string - 为什么 utf8 与 ascii 兼容

javascript - ASCII 代码在 Firefox 中不起作用,但在 Chrome 上工作正常

c++ - < 变为 > 时,如何优雅地避免代码重复?

node.js - Node : loading ES Modules and native addons in the same project

google-chrome - 将 Chrome (hunspell) 中的两个 BDIC 文件合二为一

python - pip 安装 hunspell : Cannot open include file: 'hunspell.h' : No such file or directory