47 lines
1.3 KiB
Diff
47 lines
1.3 KiB
Diff
From 05b478aa0b743794d3858c2c195574a09ba4075b Mon Sep 17 00:00:00 2001
|
|
From: yangfeng <yangfeng@kylinsec.com.cn>
|
|
Date: Mon, 8 Jan 2024 15:34:48 +0800
|
|
Subject: [PATCH 4/5] fix(common):Fix Pinyin search failed when
|
|
/etc/locale.conf is not LANG="zh_CN.UTF-8"
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
- 修复当 /etc/locale.conf 不是 LANG="zh_CN.UTF-8" 时,拼音搜索失败
|
|
|
|
Related #21369
|
|
---
|
|
lib/common.cpp | 9 +++++++++
|
|
1 file changed, 9 insertions(+)
|
|
|
|
diff --git a/lib/common.cpp b/lib/common.cpp
|
|
index a2f8567..bcd0890 100644
|
|
--- a/lib/common.cpp
|
|
+++ b/lib/common.cpp
|
|
@@ -53,6 +53,12 @@ convert_chars_to_wchars(const std::string &contents)
|
|
size_t mbs_len;
|
|
wchar_t *wcs;
|
|
|
|
+ // mbstowcs 依赖全局 locale && GTK+中只认 UTF-8
|
|
+ // 当 /etc/locale.conf 为 zh_CN.utf8 时,结果正常; 当为 zh_CN.GB18030 时,结果不正常
|
|
+ // 所以此处需要设置为 utf-8
|
|
+ std::string prev_loc = std::setlocale(LC_CTYPE, nullptr);
|
|
+ setlocale(LC_CTYPE, "C.utf8");
|
|
+
|
|
mbs_len = mbstowcs(NULL, contents.c_str(), 0);
|
|
if (mbs_len == (size_t)-1)
|
|
{
|
|
@@ -70,6 +76,9 @@ convert_chars_to_wchars(const std::string &contents)
|
|
free(wcs);
|
|
return NULL;
|
|
}
|
|
+
|
|
+ // 还原
|
|
+ std::setlocale(LC_CTYPE, prev_loc.c_str());
|
|
|
|
return wcs;
|
|
}
|
|
--
|
|
2.27.0
|
|
|