如何在Windows路径中使用非ASCII字符加载hunspell词典? [英] How to load hunspell dictionary in Windows path with non-ASCII characters?

查看:148
本文介绍了如何在Windows路径中使用非ASCII字符加载hunspell词典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

Hunspell手册建议:

在WIN32中 环境中,请使用以长路径前缀\?\开头的UTF-8编码路径来处理 与系统无关的字符编码和非常长的路径名.

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.

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

So I have code to do the following:

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";

此前缀\\?\到路径,使用一致的目录分隔符,如

This prefixes \\?\ to the path, uses a consistent directory separator as documented by the note in microsoft documentation, and converts it to UTF-8 encoding with .toUtf8().

但是在Windows 10 Pro上运行代码失败:

Yet running the code out on Windows 10 Pro fails:

如何解决?

使用Qt5,MinGW 7.3.0.

Using Qt5, MinGW 7.3.0.

我也进行了适当的研究,据我所知,LibreOffice可以做同样的事情,并且似乎可以为他们服务:

I've also done due research and as far as I can see, LibreOffice does the same thing and it seemingly works for them: sspellimp.cxx, lingutil.hxx, and lingutil.cxx.

推荐答案

您可以使用 QTIFW-175 .

You can use GetShortPathNameW to obtain a pure-ASCII path that Hunspell will understand. See QTIFW-175 for an example.

(感谢 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆