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

app name case insensitive in app_options #1049

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 7 additions & 5 deletions RimeWithWeasel/RimeWithWeasel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
{
Expand Down
13 changes: 12 additions & 1 deletion include/RimeWithWeasel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down