Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opencc中文路径问题 #654

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/rime/gear/simplifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <opencc/Dict.hpp>
#include <opencc/DictEntry.hpp>

#ifdef WIN32
#include <Windows.h>
#endif

static const char* quote_left = "\xe3\x80\x94"; //"\xef\xbc\x88";
static const char* quote_right = "\xe3\x80\x95"; //"\xef\xbc\x89";

Expand All @@ -36,7 +40,21 @@ class Opencc {
LOG(INFO) << "initializing opencc: " << config_path;
opencc::Config config;
try {
#ifdef WIN32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议把这段提炼成单个方法,方便其他地方引用

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或者也可以使用 OpenCC 的方法来实现,这样就不用自己费劲写了:

https://github.com/BYVoid/OpenCC/blob/5750d92a92ac1f2d64c880c1f6f1a5e382d7d199/src/UTF8Util.hpp#L256-L289

Copy link
Author

@Techince Techince Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

似乎只有Windows平台使用多字节字符串路径,这个转换只有opencc会用到,别的地方用不到了。其它平台在这里传入的是utf8,Windows平台传入的却是多字节,而opencc要求必须传入utf8字符串。

// 将多字节转换为宽字节
auto len = MultiByteToWideChar(CP_ACP, 0, config_path.data(), -1, nullptr, 0);
std::wstring buffer(len, 0);
MultiByteToWideChar(CP_ACP, 0, config_path.data(), -1, &buffer[0], len);

// 将宽字节转换为UTF8
len = WideCharToMultiByte(CP_UTF8, 0, buffer.data(), -1, nullptr, 0, nullptr, nullptr);
std::string path(len, 0);
WideCharToMultiByte(CP_UTF8, 0, buffer.data(), -1, &path[0], len, 0, 0);

converter_ = config.NewFromFile(path);
#else
converter_ = config.NewFromFile(config_path);
#endif
const list<opencc::ConversionPtr> conversions =
converter_->GetConversionChain()->GetConversions();
dict_ = conversions.front()->GetDict();
Expand Down
5 changes: 5 additions & 0 deletions src/rime/lever/custom_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ bool CustomSettings::Load() {
fs::path custom_config_path =
fs::path(deployer_->user_data_dir) / custom_config_file(config_id_);
if (!custom_config_.LoadFromFile(custom_config_path.string())) {
#ifdef WIN32
LOG(INFO) << "creating new file '" << custom_config_file(config_id_).c_str() << "'.";
std::ofstream out{ custom_config_path.string(), std::ios::app };
#else
return false;
#endif
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前是改过的。但梁大说这两个文件在Weasel端创建,librime是几个平台共用的库,不应该创建平台相关的文件。所以就删除了。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, 我的意思是行尾不应该多个空格, 让你困扰了。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在网页上改的,有时候空格没注意到。文件当时是本机编译的,环境变量不太一样,用github同步时会冲突,只网页上修改了相关的代码片断。

modified_ = false;
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/rime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" {
#define RIME_API
#endif /* _WIN32 */

typedef uintptr_t RimeSessionId;
typedef uintptr_t RimeSessionId; // 编译时此处不变。引用到项目时,建议将其修改为「using RimeSessionId = UINT64;」

typedef int Bool;

Expand Down