diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-18 21:25:44 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-18 21:25:44 +0800 |
| commit | df2dadbd0f0ace6e02281c84218537ec2ce5c47f (patch) | |
| tree | 56a360c16c4ba46658572305d3a444fb30d32272 /src/platform/gui/win/InputMethod.cpp | |
| parent | 3648f669cb42cdd9d232d60c8b9715dfbbe5b31a (diff) | |
| download | cru-df2dadbd0f0ace6e02281c84218537ec2ce5c47f.tar.gz cru-df2dadbd0f0ace6e02281c84218537ec2ce5c47f.tar.bz2 cru-df2dadbd0f0ace6e02281c84218537ec2ce5c47f.zip | |
Add overload of string_view for string utils. clean up codes.
Diffstat (limited to 'src/platform/gui/win/InputMethod.cpp')
| -rw-r--r-- | src/platform/gui/win/InputMethod.cpp | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/platform/gui/win/InputMethod.cpp b/src/platform/gui/win/InputMethod.cpp index c5aca657..812670e1 100644 --- a/src/platform/gui/win/InputMethod.cpp +++ b/src/platform/gui/win/InputMethod.cpp @@ -123,7 +123,7 @@ CompositionText GetCompositionInfo(HIMC imm_context) { // convert them into underlines and selection range respectively. auto utf16_text = GetString(imm_context); - auto text = string::ToUtf8(utf16_text); + auto text = string::ToUtf8String(utf16_text); int length = static_cast<int>(utf16_text.length()); // Find out the range selected by the user. @@ -134,23 +134,15 @@ CompositionText GetCompositionInfo(HIMC imm_context) { auto clauses = GetCompositionClauses(imm_context, target_start, target_end); for (auto& clause : clauses) { clause.start = string::Utf8IndexCodePointToCodeUnit( - text.data(), text.size(), - string::Utf16IndexCodeUnitToCodePoint( - reinterpret_cast<const char16_t*>(utf16_text.data()), - utf16_text.size(), clause.start)); + text, string::Utf16IndexCodeUnitToCodePoint(utf16_text, clause.start)); clause.end = string::Utf8IndexCodePointToCodeUnit( - text.data(), text.size(), - string::Utf16IndexCodeUnitToCodePoint( - reinterpret_cast<const char16_t*>(utf16_text.data()), - utf16_text.size(), clause.end)); + text, string::Utf16IndexCodeUnitToCodePoint(utf16_text, clause.end)); } int cursor = string::Utf8IndexCodePointToCodeUnit( - text.data(), text.size(), - string::Utf16IndexCodeUnitToCodePoint( - reinterpret_cast<const char16_t*>(utf16_text.data()), - utf16_text.size(), - ::ImmGetCompositionString(imm_context, GCS_CURSORPOS, NULL, 0))); + text, string::Utf16IndexCodeUnitToCodePoint( + utf16_text, ::ImmGetCompositionString(imm_context, + GCS_CURSORPOS, NULL, 0))); return CompositionText{std::move(text), std::move(clauses), TextRange{cursor}}; @@ -229,7 +221,9 @@ IEvent<std::nullptr_t>* WinInputMethodContext::CompositionEvent() { return &composition_event_; } -IEvent<const std::string&>* WinInputMethodContext::TextEvent() { return &text_event_; } +IEvent<const std::string&>* WinInputMethodContext::TextEvent() { + return &text_event_; +} void WinInputMethodContext::OnWindowNativeMessage( WindowNativeMessageEventArgs& args) { @@ -286,7 +280,7 @@ void WinInputMethodContext::OnWindowNativeMessage( std::string WinInputMethodContext::GetResultString() { auto himc = GetHIMC(); auto result = win::GetResultString(himc.Get()); - return string::ToUtf8(result); + return string::ToUtf8String(result); } AutoHIMC WinInputMethodContext::GetHIMC() { |
