Skip to content

Commit 30e5adf

Browse files
committed
refactor(WeaselDeployer): string convertions with macro
1 parent aba0609 commit 30e5adf

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

WeaselDeployer/Configurator.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
#include "WeaselDeployer.h"
1919

2020
static void CreateFileIfNotExist(std::string filename) {
21-
std::filesystem::path file_path =
22-
WeaselUserDataPath() / string_to_wstring(filename, CP_UTF8);
21+
std::filesystem::path file_path = WeaselUserDataPath() / u8tow(filename);
2322
DWORD dwAttrib = GetFileAttributes(file_path.c_str());
2423
if (!(INVALID_FILE_ATTRIBUTES != dwAttrib &&
2524
0 == (dwAttrib & FILE_ATTRIBUTE_DIRECTORY))) {
@@ -34,15 +33,12 @@ Configurator::Configurator() {
3433

3534
void Configurator::Initialize() {
3635
RIME_STRUCT(RimeTraits, weasel_traits);
37-
std::string shared_dir =
38-
wstring_to_string(WeaselSharedDataPath().wstring(), CP_UTF8);
39-
std::string user_dir =
40-
wstring_to_string(WeaselUserDataPath().wstring(), CP_UTF8);
36+
std::string shared_dir = wtou8(WeaselSharedDataPath().wstring());
37+
std::string user_dir = wtou8(WeaselUserDataPath().wstring());
4138
weasel_traits.shared_data_dir = shared_dir.c_str();
4239
weasel_traits.user_data_dir = user_dir.c_str();
4340
weasel_traits.prebuilt_data_dir = weasel_traits.shared_data_dir;
44-
std::string distribution_name =
45-
wstring_to_string(get_weasel_ime_name(), CP_UTF8);
41+
std::string distribution_name = wtou8(get_weasel_ime_name());
4642
weasel_traits.distribution_name = distribution_name.c_str();
4743
weasel_traits.distribution_code_name = WEASEL_CODE_NAME;
4844
weasel_traits.distribution_version = WEASEL_VERSION;

WeaselDeployer/DictManagementDialog.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void DictManagementDialog::Populate() {
6767
RimeUserDictIterator iter = {0};
6868
api_->user_dict_iterator_init(&iter);
6969
while (const char* dict = api_->next_user_dict(&iter)) {
70-
std::wstring txt = string_to_wstring(dict, CP_UTF8);
70+
std::wstring txt = u8tow(dict);
7171
user_dict_list_.AddString(txt.c_str());
7272
}
7373
api_->user_dict_iterator_destroy(&iter);
@@ -121,7 +121,7 @@ LRESULT DictManagementDialog::OnBackup(WORD, WORD code, HWND, BOOL&) {
121121
WCHAR dict_name[100] = {0};
122122
user_dict_list_.GetText(sel, dict_name);
123123
path += std::wstring(L"\\") + dict_name + L".userdb.txt";
124-
std::string dict_name_str = wstring_to_string(dict_name, CP_UTF8);
124+
std::string dict_name_str = wtou8(dict_name);
125125
if (!api_->backup_user_dict(dict_name_str.c_str())) {
126126
MSG_BY_IDS(IDS_STR_ERR_EXPORT_UNKNOWN, IDS_STR_SAD, MB_OK | MB_ICONERROR);
127127
return 0;
@@ -200,7 +200,7 @@ LRESULT DictManagementDialog::OnExport(WORD, WORD code, HWND, BOOL&) {
200200
char path[MAX_PATH] = {0};
201201
WideCharToMultiByte(CP_UTF8, 0, selected_path.c_str(), -1, path,
202202
_countof(path), NULL, NULL);
203-
std::string dict_name_str = wstring_to_string(dict_name, CP_UTF8);
203+
std::string dict_name_str = wtou8(dict_name);
204204
int result = api_->export_user_dict(dict_name_str.c_str(), path);
205205
if (result < 0) {
206206
MSG_BY_IDS(IDS_STR_ERR_UNKNOWN, IDS_STR_SAD, MB_OK | MB_ICONERROR);
@@ -250,8 +250,7 @@ LRESULT DictManagementDialog::OnImport(WORD, WORD code, HWND, BOOL&) {
250250
char path[MAX_PATH] = {0};
251251
WideCharToMultiByte(CP_UTF8, 0, selected_path.c_str(), -1, path,
252252
_countof(path), NULL, NULL);
253-
int result = api_->import_user_dict(
254-
wstring_to_string(dict_name, CP_UTF8).c_str(), path);
253+
int result = api_->import_user_dict(wtou8(dict_name).c_str(), path);
255254
if (result < 0) {
256255
MSG_BY_IDS(IDS_STR_ERR_UNKNOWN, IDS_STR_SAD, MB_OK | MB_ICONERROR);
257256
} else {

WeaselDeployer/SwitcherSettingsDialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void SwitcherSettingsDialog::Populate() {
3232
if (!strcmp(item.schema_id, schema_id) &&
3333
recruited.find(info) == recruited.end()) {
3434
recruited.insert(info);
35-
std::wstring itemwstr = string_to_wstring(item.name, CP_UTF8);
35+
std::wstring itemwstr = u8tow(item.name);
3636
schema_list_.AddItem(k, 0, itemwstr.c_str());
3737
schema_list_.SetItemData(k, (DWORD_PTR)info);
3838
schema_list_.SetCheckState(k, TRUE);
@@ -46,13 +46,13 @@ void SwitcherSettingsDialog::Populate() {
4646
RimeSchemaInfo* info = (RimeSchemaInfo*)item.reserved;
4747
if (recruited.find(info) == recruited.end()) {
4848
recruited.insert(info);
49-
std::wstring itemwstr = string_to_wstring(item.name, CP_UTF8);
49+
std::wstring itemwstr = u8tow(item.name);
5050
schema_list_.AddItem(k, 0, itemwstr.c_str());
5151
schema_list_.SetItemData(k, (DWORD_PTR)info);
5252
++k;
5353
}
5454
}
55-
std::wstring txt = string_to_wstring(api_->get_hotkeys(settings_), CP_UTF8);
55+
std::wstring txt = u8tow(api_->get_hotkeys(settings_));
5656
hotkeys_.SetWindowTextW(txt.c_str());
5757
loaded_ = true;
5858
modified_ = false;
@@ -71,7 +71,7 @@ void SwitcherSettingsDialog::ShowDetails(RimeSchemaInfo* info) {
7171
if (const char* description = api_->get_schema_description(info)) {
7272
(details += "\n\n") += description;
7373
}
74-
std::wstring txt = string_to_wstring(details.c_str(), CP_UTF8);
74+
std::wstring txt = u8tow(details.c_str());
7575
description_.SetWindowTextW(txt.c_str());
7676
}
7777

WeaselDeployer/UIStyleSettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bool UIStyleSettings::GetPresetColorSchemes(
4040

4141
// check if a file exists
4242
static inline bool IfFileExist(std::string filename) {
43-
DWORD dwAttrib = GetFileAttributes(string_to_wstring(filename).c_str());
43+
DWORD dwAttrib = GetFileAttributes(acptow(filename).c_str());
4444
return (INVALID_FILE_ATTRIBUTES != dwAttrib &&
4545
0 == (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
4646
}

WeaselDeployer/UIStyleSettingsDialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void UIStyleSettingsDialog::Populate() {
1818
int active_index = -1;
1919
settings_->GetPresetColorSchemes(&preset_);
2020
for (size_t i = 0; i < preset_.size(); ++i) {
21-
std::wstring txt = string_to_wstring(preset_[i].name.c_str(), CP_UTF8);
21+
std::wstring txt = u8tow(preset_[i].name);
2222
color_schemes_.AddString(txt.c_str());
2323
if (preset_[i].color_scheme_id == active) {
2424
active_index = i;
@@ -72,7 +72,7 @@ void UIStyleSettingsDialog::Preview(int index) {
7272
return;
7373
image_.Destroy();
7474
// it is from ansi coding, not utf8
75-
image_.Load(string_to_wstring(file_path).c_str());
75+
image_.Load(acptow(file_path).c_str());
7676
if (!image_.IsNull()) {
7777
preview_.SetBitmap(image_);
7878
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy