Repository: rime/weasel (language: cpp)

Issue:
feature request: app_options 匹配进程名不区分大小写
- Windows 显示的进程名是大小写兼具的，
- 系统大小写不敏感

但在 app_options 中，得全小写才能匹配。

从任务管理器等出复制的进程名，到 weasel.yaml 还得全小写，有一些反直觉？碰到了不少新手在这里栽跟头了

有没有可能改成不区分大小写匹配？或者说目前的设计是有意为之？


Discussion / hints:
全小写是之前的有意为之，具体原因不详
https://github.com/rime/weasel/blob/master/WeaselIPC/WeaselClientImpl.cpp#L44

Fix patch:
diff --git a/RimeWithWeasel/RimeWithWeasel.cpp b/RimeWithWeasel/RimeWithWeasel.cpp
index 18d0d7340..c7c246dd5 100644
--- a/RimeWithWeasel/RimeWithWeasel.cpp
+++ b/RimeWithWeasel/RimeWithWeasel.cpp
@@ -296,9 +296,10 @@ void RimeWithWeaselHandler::_ReadClientInfo(UINT session_id, LPWSTR buffer)
 	{
 		RimeSetProperty(session_id, "client_app", app_name.c_str());
 
-		if (m_app_options.find(app_name) != m_app_options.end())
+		auto it = m_app_options.find(app_name);
+		if (it != m_app_options.end())
 		{
-			AppOptions& options(m_app_options[app_name]);
+			AppOptions& options(m_app_options[it->first]);
 			std::for_each(options.begin(), options.end(), [session_id](std::pair<const std::string, bool> &pair)
 			{
 				DLOG(INFO) << "set app option: " << pair.first << " = " << pair.second;
@@ -494,11 +495,12 @@ void RimeWithWeaselHandler::_LoadAppInlinePreeditSet(UINT session_id, bool ignor
 	bool inline_preedit = m_ui->style().inline_preedit;
 	if (!app_name.empty())
 	{
-		if (m_app_options.find(app_name) != m_app_options.end())
+		auto it = m_app_options.find(app_name);
+		if (it != m_app_options.end())
 		{
-			AppOptions& options(m_app_options[app_name]);
+			AppOptions& options(m_app_options[it->first]);
 			auto pfind = std::make_shared<bool>(false);
-			std::for_each(options.begin(), options.end(), [session_id, app_name, pfind, inline_preedit, this](std::pair<const std::string, bool> &pair)
+			std::for_each(options.begin(), options.end(), [session_id, pfind, inline_preedit, this](std::pair<const std::string, bool> &pair)
 			{
 			if(pair.first == "inline_preedit")
 			{
diff --git a/include/RimeWithWeasel.h b/include/RimeWithWeasel.h
index e44645eaa..650ca0d6f 100644
--- a/include/RimeWithWeasel.h
+++ b/include/RimeWithWeasel.h
@@ -6,8 +6,19 @@
 
 #include <rime_api.h>
 
+struct CaseInsensitiveCompare {
+	bool operator()(const std::string& str1, const std::string& str2) const {
+		std::string str1Lower, str2Lower;
+		std::transform(str1.begin(), str1.end(), std::back_inserter(str1Lower),
+				[](char c) { return std::tolower(c); });
+		std::transform(str2.begin(), str2.end(), std::back_inserter(str2Lower),
+				[](char c) { return std::tolower(c); });
+		return str1Lower < str2Lower;
+	}
+};
+
 typedef std::map<std::string, bool> AppOptions;
-typedef std::map<std::string, AppOptions> AppOptionsByAppName;
+typedef std::map<std::string, AppOptions, CaseInsensitiveCompare> AppOptionsByAppName;
 class RimeWithWeaselHandler :
 	public weasel::RequestHandler
 {


Test patch: