如何在 Windows 路径中加载非 ASCII 字符的 hunspell 字典?

How to load hunspell dictionary in Windows path with non-ASCII characters?

如何在包含非 ASCII 字符的 Windows 路径中加载 hunspell 字典?

Hunspell manual 建议:

In WIN32 environment, use UTF-8 encoded paths started with the long path prefix \?\ to handle system-independent character encoding and very long path names, too.

所以我有代码可以执行以下操作:

QString spell_aff = QStringLiteral(R"(\?\%1%2.aff)").arg(path, newDict);
QString spell_dic = QStringLiteral(R"(\?\%1%2.dic)").arg(path, newDict);
// while normally not a an issue, you can't mix forward and back slashes with the prefix
spell_dic = spell_aff.replace(QChar('/'), QStringLiteral("\"));
spell_dic = spell_dic.replace(QChar('/'), QStringLiteral("\"));

qDebug() << "right before Hunspell_create";
mpHunspell_system = Hunspell_create(spell_aff.toUtf8().constData(), spell_dic.toUtf8().constData());
qDebug() << "right after Hunspell_create";

此前缀 \?\ 到路径,使用一致的目录分隔符,如 microsoft documentation, and converts it to UTF-8 encoding with .toUtf8() 中的注释所述。

然而 运行 Windows 10 Pro 上的代码失败:

如何修复?

使用 Qt5、MinGW 7.3.0。

我也做了适当的研究,据我所知,LibreOffice 做同样的事情,而且它似乎对他们有效:sspellimp.cxx, lingutil.hxx, and lingutil.cxx.

您可以使用 GetShortPathNameW to obtain a pure-ASCII path that Hunspell will understand. See QTIFW-175 作为示例。

(感谢