diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/base/StringUtil.cpp | 4 | ||||
| -rw-r--r-- | src/base/log/StdioLogTarget.cpp | 2 | ||||
| -rw-r--r-- | src/base/platform/win/DebugLogTarget.cpp | 2 | ||||
| -rw-r--r-- | src/base/platform/win/Stream.cpp | 4 | ||||
| -rw-r--r-- | src/base/platform/win/Win32SubProcess.cpp | 8 | ||||
| -rw-r--r-- | src/platform/graphics/cairo/PangoTextLayout.cpp | 3 | ||||
| -rw-r--r-- | src/platform/graphics/direct2d/Font.cpp | 2 | ||||
| -rw-r--r-- | src/platform/graphics/direct2d/TextLayout.cpp | 26 | ||||
| -rw-r--r-- | src/platform/graphics/quartz/TextLayout.cpp | 28 | ||||
| -rw-r--r-- | src/platform/gui/osx/Window.mm | 19 | ||||
| -rw-r--r-- | src/platform/gui/win/Clipboard.cpp | 4 | ||||
| -rw-r--r-- | src/platform/gui/win/InputMethod.cpp | 26 | ||||
| -rw-r--r-- | src/platform/gui/win/Window.cpp | 4 | ||||
| -rw-r--r-- | src/ui/controls/TextHostControlService.cpp | 34 |
14 files changed, 71 insertions, 95 deletions
diff --git a/src/base/StringUtil.cpp b/src/base/StringUtil.cpp index a5cc3122..eaa3f58e 100644 --- a/src/base/StringUtil.cpp +++ b/src/base/StringUtil.cpp @@ -404,7 +404,7 @@ Index Utf16IndexCodePointToCodeUnit(const Utf16CodeUnit* ptr, Index size, } #ifdef _WIN32 -std::wstring ToUtf16(std::string_view str) { +std::wstring ToUtf16WString(std::string_view str) { Utf8CodePointIterator iter(str.data(),str.size()); std::wstring result; for (auto c : iter) { @@ -413,7 +413,7 @@ std::wstring ToUtf16(std::string_view str) { return result; } -std::string ToUtf8(std::wstring_view str) { +std::string ToUtf8String(std::wstring_view str) { Utf16CodePointIterator iter(reinterpret_cast<const char16_t*>( str.data()),str.size()); std::string result; for (auto c : iter) { diff --git a/src/base/log/StdioLogTarget.cpp b/src/base/log/StdioLogTarget.cpp index bdcdd783..4b77f755 100644 --- a/src/base/log/StdioLogTarget.cpp +++ b/src/base/log/StdioLogTarget.cpp @@ -10,7 +10,7 @@ StdioLogTarget::~StdioLogTarget() {} void StdioLogTarget::Write(log::LogLevel level, std::string message) { #ifdef _WIN32 - auto s = string::ToUtf16(message); + auto s = string::ToUtf16WString(message); if (level == log::LogLevel::Error) { std::wcerr << s << std::endl; } else { diff --git a/src/base/platform/win/DebugLogTarget.cpp b/src/base/platform/win/DebugLogTarget.cpp index 3b73b332..d6dc1d95 100644 --- a/src/base/platform/win/DebugLogTarget.cpp +++ b/src/base/platform/win/DebugLogTarget.cpp @@ -6,7 +6,7 @@ namespace cru::platform::win { void WinDebugLogTarget::Write(::cru::log::LogLevel level, std::string s) { CRU_UNUSED(level) - std::wstring m = string::ToUtf16(s); + std::wstring m = string::ToUtf16WString(s); ::OutputDebugStringW(reinterpret_cast<const wchar_t*>(m.c_str())); } } // namespace cru::platform::win diff --git a/src/base/platform/win/Stream.cpp b/src/base/platform/win/Stream.cpp index d4b24d64..72466905 100644 --- a/src/base/platform/win/Stream.cpp +++ b/src/base/platform/win/Stream.cpp @@ -43,7 +43,7 @@ HANDLE OpenHandle(std::string_view path, OpenFileFlag flags) { IStream* stream; auto handle = - ::CreateFileW(cru::string::ToUtf16(path).c_str(), access, 0, nullptr, + ::CreateFileW(cru::string::ToUtf16WString(path).c_str(), access, 0, nullptr, creation_disposition, FILE_ATTRIBUTE_NORMAL, nullptr); if (handle == INVALID_HANDLE_VALUE) { @@ -163,7 +163,7 @@ IStream* OpenComStream(std::string_view path, OpenFileFlag flags) { IStream* stream; CheckHResult(SHCreateStreamOnFileEx( - cru::string::ToUtf16(path).c_str(), grfMode, FILE_ATTRIBUTE_NORMAL, + cru::string::ToUtf16WString(path).c_str(), grfMode, FILE_ATTRIBUTE_NORMAL, flags & io::OpenFileFlags::Create ? TRUE : FALSE, NULL, &stream)); return stream; diff --git a/src/base/platform/win/Win32SubProcess.cpp b/src/base/platform/win/Win32SubProcess.cpp index c97f3d66..aed3937c 100644 --- a/src/base/platform/win/Win32SubProcess.cpp +++ b/src/base/platform/win/Win32SubProcess.cpp @@ -8,7 +8,7 @@ #include <string_view> namespace cru::platform::win { -using cru::string::ToUtf16; +using cru::string::ToUtf16WString; Win32SubProcessImpl::Win32SubProcessImpl() : exit_code_(0) {} @@ -23,14 +23,14 @@ void Win32SubProcessImpl::PlatformCreateProcess( std::move(inner)); }; - auto app = ToUtf16(start_info.program); + auto app = ToUtf16WString(start_info.program); // TODO: Space and quoting problem. auto command_line = - app + L" " + ToUtf16(cru::string::Join(" ", start_info.arguments)); + app + L" " + ToUtf16WString(cru::string::Join(" ", start_info.arguments)); std::wstring env_str; for (const auto& [key, value] : start_info.environments) { - env_str += ToUtf16(key) + L"=" + ToUtf16(value) + L"\0"; + env_str += ToUtf16WString(key) + L"=" + ToUtf16WString(value) + L"\0"; } env_str += L"\0"; diff --git a/src/platform/graphics/cairo/PangoTextLayout.cpp b/src/platform/graphics/cairo/PangoTextLayout.cpp index 25d9f85d..98ad4f45 100644 --- a/src/platform/graphics/cairo/PangoTextLayout.cpp +++ b/src/platform/graphics/cairo/PangoTextLayout.cpp @@ -165,8 +165,7 @@ TextHitTestResult PangoTextLayout::HitTest(const Point& point) { if (result.trailing) { Index position_with_trailing; - string::Utf8NextCodePoint(text_.data(), text_.size(), result.position, - &position_with_trailing); + string::Utf8NextCodePoint(text_, result.position, &position_with_trailing); result.position_with_trailing = position_with_trailing; } else { result.position_with_trailing = result.position; diff --git a/src/platform/graphics/direct2d/Font.cpp b/src/platform/graphics/direct2d/Font.cpp index 18a4a2c7..4e0a5e49 100644 --- a/src/platform/graphics/direct2d/Font.cpp +++ b/src/platform/graphics/direct2d/Font.cpp @@ -17,7 +17,7 @@ DWriteFont::DWriteFont(DirectGraphicsFactory* factory, std::string font_family, ::GetLastError(), "Failed to get locale when create dwrite font."); CheckHResult(factory->GetDWriteFactory()->CreateTextFormat( - string::ToUtf16(font_family_).c_str(), nullptr, DWRITE_FONT_WEIGHT_NORMAL, + string::ToUtf16WString(font_family_).c_str(), nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, font_size, buffer.data(), &text_format_)); diff --git a/src/platform/graphics/direct2d/TextLayout.cpp b/src/platform/graphics/direct2d/TextLayout.cpp index 3fc91616..18784ccb 100644 --- a/src/platform/graphics/direct2d/TextLayout.cpp +++ b/src/platform/graphics/direct2d/TextLayout.cpp @@ -13,7 +13,7 @@ DWriteTextLayout::DWriteTextLayout(DirectGraphicsFactory* factory, Expects(font); font_ = CheckPlatform<DWriteFont>(font, GetPlatformId()); - utf16_text_ = string::ToUtf16(text_); + utf16_text_ = string::ToUtf16WString(text_); CheckHResult(factory->GetDWriteFactory()->CreateTextLayout( utf16_text_.c_str(), static_cast<UINT32>(utf16_text_.size()), font_->GetComInterface(), max_width_, max_height_, &text_layout_)); @@ -25,7 +25,7 @@ std::string DWriteTextLayout::GetText() { return text_; } void DWriteTextLayout::SetText(std::string new_text) { text_ = std::move(new_text); - utf16_text_ = string::ToUtf16(text_); + utf16_text_ = string::ToUtf16WString(text_); CheckHResult(GetDirectFactory()->GetDWriteFactory()->CreateTextLayout( utf16_text_.c_str(), static_cast<UINT32>(utf16_text_.size()), font_->GetComInterface(), max_width_, max_height_, &text_layout_)); @@ -108,15 +108,11 @@ std::vector<Rect> DWriteTextLayout::TextRangeRect( const auto text_range = Range::FromTwoSides( string::Utf16IndexCodePointToCodeUnit( - reinterpret_cast<const char16_t*>(utf16_text_.data()), - utf16_text_.size(), - string::Utf8IndexCodeUnitToCodePoint(text_.data(), text_.size(), - text_range_arg.GetStart())), + utf16_text_, string::Utf8IndexCodeUnitToCodePoint( + text_, text_range_arg.GetStart())), string::Utf16IndexCodePointToCodeUnit( - reinterpret_cast<const char16_t*>(utf16_text_.data()), - utf16_text_.size(), - string::Utf8IndexCodeUnitToCodePoint(text_.data(), text_.size(), - text_range_arg.GetEnd()))) + utf16_text_, string::Utf8IndexCodeUnitToCodePoint( + text_, text_range_arg.GetEnd()))) .Normalize(); DWRITE_TEXT_METRICS text_metrics; @@ -147,9 +143,7 @@ std::vector<Rect> DWriteTextLayout::TextRangeRect( Rect DWriteTextLayout::TextSinglePoint(Index position, bool trailing) { position = string::Utf16IndexCodePointToCodeUnit( - reinterpret_cast<const char16_t*>(utf16_text_.data()), utf16_text_.size(), - string::Utf8IndexCodeUnitToCodePoint(text_.data(), text_.size(), - position)); + utf16_text_, string::Utf8IndexCodeUnitToCodePoint(text_, position)); DWRITE_HIT_TEST_METRICS metrics; FLOAT left; FLOAT top; @@ -169,10 +163,8 @@ TextHitTestResult DWriteTextLayout::HitTest(const Point& point) { TextHitTestResult result; result.position = string::Utf8IndexCodePointToCodeUnit( - text_.data(), text_.size(), - string::Utf16IndexCodeUnitToCodePoint( - reinterpret_cast<const char16_t*>(utf16_text_.data()), - utf16_text_.size(), metrics.textPosition)); + text_, + string::Utf16IndexCodeUnitToCodePoint(utf16_text_, metrics.textPosition)); result.trailing = trailing != 0; if (result.trailing) { diff --git a/src/platform/graphics/quartz/TextLayout.cpp b/src/platform/graphics/quartz/TextLayout.cpp index 4793a19c..80cb8a3f 100644 --- a/src/platform/graphics/quartz/TextLayout.cpp +++ b/src/platform/graphics/quartz/TextLayout.cpp @@ -238,28 +238,25 @@ TextHitTestResult OsxCTTextLayout::HitTest(const Point& point) { bool inside_text; if (pp.x < bounds.origin.x) { - po = cru::string::Utf8IndexCodePointToCodeUnit( - actual_text_.data(), actual_text_.size(), range.location); + po = cru::string::Utf8IndexCodePointToCodeUnit(actual_text_, + range.location); inside_text = false; } else if (pp.x > bounds.origin.x + bounds.size.width) { po = cru::string::Utf8IndexCodePointToCodeUnit( - actual_text_.data(), actual_text_.size(), - range.location + range.length); + actual_text_, range.location + range.length); inside_text = false; } else { int position = CTLineGetStringIndexForPosition( line, CGPointMake(pp.x - line_origins_[i].x, pp.y - line_origins_[i].y)); - po = cru::string::Utf8IndexCodePointToCodeUnit( - actual_text_.data(), actual_text_.size(), position); + po = cru::string::Utf8IndexCodePointToCodeUnit(actual_text_, position); inside_text = true; } if (po != 0 && po == cru::string::Utf8IndexCodePointToCodeUnit( - actual_text_.data(), actual_text_.size(), - range.location + range.length) && + actual_text_, range.location + range.length) && actual_text_[po - 1] == u'\n') { --po; } @@ -405,13 +402,11 @@ CGRect OsxCTTextLayout::DoGetTextBoundsIncludingEmptyLines( std::vector<CGRect> OsxCTTextLayout::DoTextRangeRect( const TextRange& text_range) { - const auto r = - Range::FromTwoSides( - cru::string::Utf8IndexCodeUnitToCodePoint( - actual_text_.data(), actual_text_.size(), text_range.position), - cru::string::Utf8IndexCodeUnitToCodePoint( - actual_text_.data(), actual_text_.size(), text_range.GetEnd())) - .Normalize(); + const auto r = Range::FromTwoSides(cru::string::Utf8IndexCodeUnitToCodePoint( + actual_text_, text_range.position), + cru::string::Utf8IndexCodeUnitToCodePoint( + actual_text_, text_range.GetEnd())) + .Normalize(); std::vector<CGRect> results; @@ -443,8 +438,7 @@ CGRect OsxCTTextLayout::DoTextSinglePoint(Index position, bool trailing) { if (actual_text_.empty()) return CGRectMake(0, 0, 0, font_->GetFontSize()); - position = cru::string::Utf8IndexCodeUnitToCodePoint( - actual_text_.data(), actual_text_.size(), position); + position = cru::string::Utf8IndexCodeUnitToCodePoint(actual_text_, position); for (int i = 0; i < line_count_; i++) { auto line = lines_[i]; diff --git a/src/platform/gui/osx/Window.mm b/src/platform/gui/osx/Window.mm index 167adfc5..2d30724f 100644 --- a/src/platform/gui/osx/Window.mm +++ b/src/platform/gui/osx/Window.mm @@ -3,9 +3,9 @@ #include "CursorPrivate.h" #include "InputMethodPrivate.h" -#include "cru/base/platform/osx/Base.h" #include "cru/base/Range.h" #include "cru/base/log/Logger.h" +#include "cru/base/platform/osx/Base.h" #include "cru/platform/graphics/NullPainter.h" #include "cru/platform/graphics/quartz/Painter.h" #include "cru/platform/gui/Input.h" @@ -384,9 +384,15 @@ IEvent<MouseEnterLeaveType>* OsxWindow::MouseEnterLeaveEvent() { return &p_->mouse_enter_leave_event_; } IEvent<const Point&>* OsxWindow::MouseMoveEvent() { return &p_->mouse_move_event_; } -IEvent<const NativeMouseButtonEventArgs&>* OsxWindow::MouseDownEvent() { return &p_->mouse_down_event_; } -IEvent<const NativeMouseButtonEventArgs&>* OsxWindow::MouseUpEvent() { return &p_->mouse_up_event_; } -IEvent<const NativeMouseWheelEventArgs&>* OsxWindow::MouseWheelEvent() { return &p_->mouse_wheel_event_; } +IEvent<const NativeMouseButtonEventArgs&>* OsxWindow::MouseDownEvent() { + return &p_->mouse_down_event_; +} +IEvent<const NativeMouseButtonEventArgs&>* OsxWindow::MouseUpEvent() { + return &p_->mouse_up_event_; +} +IEvent<const NativeMouseWheelEventArgs&>* OsxWindow::MouseWheelEvent() { + return &p_->mouse_wheel_event_; +} IEvent<const NativeKeyEventArgs&>* OsxWindow::KeyDownEvent() { return &p_->key_down_event_; } IEvent<const NativeKeyEventArgs&>* OsxWindow::KeyUpEvent() { return &p_->key_up_event_; } @@ -685,10 +691,9 @@ const std::unordered_set<KeyCode> input_context_handle_codes_when_has_text{ cru::platform::gui::CompositionText composition_text; composition_text.text = FromCFStringRef((CFStringRef)[_input_context_text string]); composition_text.selection.position = - cru::string::Utf8IndexCodePointToCodeUnit(ss.data(), ss.size(), selectedRange.location); + cru::string::Utf8IndexCodePointToCodeUnit(ss, selectedRange.location); composition_text.selection.count = - cru::string::Utf8IndexCodePointToCodeUnit(ss.data(), ss.size(), - selectedRange.location + selectedRange.length) - + cru::string::Utf8IndexCodePointToCodeUnit(ss, selectedRange.location + selectedRange.length) - composition_text.selection.position; _input_context_p->SetCompositionText(composition_text); _input_context_p->RaiseCompositionEvent(); diff --git a/src/platform/gui/win/Clipboard.cpp b/src/platform/gui/win/Clipboard.cpp index 7062f160..2a41a1eb 100644 --- a/src/platform/gui/win/Clipboard.cpp +++ b/src/platform/gui/win/Clipboard.cpp @@ -39,11 +39,11 @@ std::string WinClipboard::GetText() { ::GlobalUnlock(handle); ::CloseClipboard(); - return string::ToUtf8(result); + return string::ToUtf8String(result); } void WinClipboard::SetText(std::string utf8_text) { - auto text = string::ToUtf16(utf8_text); + auto text = string::ToUtf16WString(utf8_text); if (!::OpenClipboard(nullptr)) { CRU_LOG_TAG_WARN("Failed to open clipboard."); 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() { diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp index e24bb08e..02357336 100644 --- a/src/platform/gui/win/Window.cpp +++ b/src/platform/gui/win/Window.cpp @@ -96,7 +96,7 @@ void WinNativeWindow::SetTitle(std::string title) { title_ = title; if (hwnd_) { - auto utf16_text = string::ToUtf16(title); + auto utf16_text = string::ToUtf16WString(title); ::SetWindowTextW(hwnd_, utf16_text.c_str()); } } @@ -498,7 +498,7 @@ void WinNativeWindow::RecreateWindow() { SetCursor(application_->GetCursorManager()->GetSystemCursor( cru::platform::gui::SystemCursorType::Arrow)); - auto utf16_title = string::ToUtf16(title_); + auto utf16_title = string::ToUtf16WString(title_); ::SetWindowTextW(hwnd_, utf16_title.c_str()); window_render_target_ = diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp index 5908852a..5780b6d7 100644 --- a/src/ui/controls/TextHostControlService.cpp +++ b/src/ui/controls/TextHostControlService.cpp @@ -28,8 +28,7 @@ TextControlMovePattern TextControlMovePattern::kLeft( [](TextHostControlService* service, std::string_view text, Index current_position) { CRU_UNUSED(service) - Utf8PreviousCodePoint(text.data(), text.size(), current_position, - ¤t_position); + Utf8PreviousCodePoint(text, current_position, ¤t_position); return current_position; }); TextControlMovePattern TextControlMovePattern::kRight( @@ -37,8 +36,7 @@ TextControlMovePattern TextControlMovePattern::kRight( [](TextHostControlService* service, std::string_view text, Index current_position) { CRU_UNUSED(service) - Utf8NextCodePoint(text.data(), text.size(), current_position, - ¤t_position); + Utf8NextCodePoint(text, current_position, ¤t_position); return current_position; }); TextControlMovePattern TextControlMovePattern::kCtrlLeft( @@ -48,7 +46,7 @@ TextControlMovePattern TextControlMovePattern::kCtrlLeft( [](TextHostControlService* service, std::string_view text, Index current_position) { CRU_UNUSED(service) - return Utf8PreviousWord(text.data(), text.size(), current_position); + return Utf8PreviousWord(text, current_position); }); TextControlMovePattern TextControlMovePattern::kCtrlRight( "Ctrl+Right(Next Word)", @@ -57,7 +55,7 @@ TextControlMovePattern TextControlMovePattern::kCtrlRight( [](TextHostControlService* service, std::string_view text, Index current_position) { CRU_UNUSED(service) - return Utf8NextWord(text.data(), text.size(), current_position); + return Utf8NextWord(text, current_position); }); TextControlMovePattern TextControlMovePattern::kUp( "Up", helper::ShortcutKeyBind(platform::gui::KeyCode::Up), @@ -86,7 +84,7 @@ TextControlMovePattern TextControlMovePattern::kHome( [](TextHostControlService* service, std::string_view text, Index current_position) { CRU_UNUSED(service) - return Utf8BackwardUntil(text.data(), text.size(), current_position, + return Utf8BackwardUntil(text, current_position, [](CodePoint c) { return c == u'\n'; }); }); TextControlMovePattern TextControlMovePattern::kEnd( @@ -94,7 +92,7 @@ TextControlMovePattern TextControlMovePattern::kEnd( [](TextHostControlService* service, std::string_view text, Index current_position) { CRU_UNUSED(service) - return Utf8ForwardUntil(text.data(), text.size(), current_position, + return Utf8ForwardUntil(text, current_position, [](CodePoint c) { return c == u'\n'; }); }); TextControlMovePattern TextControlMovePattern::kCtrlHome( @@ -223,8 +221,7 @@ void TextHostControlService::SetText(std::string text, bool stop_composition) { void TextHostControlService::InsertText(Index position, std::string_view text, bool stop_composition) { - if (!Utf8IsValidInsertPosition(this->text_.data(), this->text_.size(), - position)) { + if (!Utf8IsValidInsertPosition(this->text_, position)) { CRU_LOG_TAG_ERROR("Invalid text insert position."); return; } @@ -238,29 +235,26 @@ void TextHostControlService::InsertText(Index position, std::string_view text, } void TextHostControlService::DeleteChar(Index position, bool stop_composition) { - if (!Utf8IsValidInsertPosition(this->text_.data(), this->text_.size(), - position)) { + if (!Utf8IsValidInsertPosition(this->text_, position)) { CRU_LOG_TAG_ERROR("Invalid text delete position {}.", position); return; } if (position == static_cast<Index>(this->text_.size())) return; Index next; - Utf8NextCodePoint(this->text_.data(), this->text_.size(), position, &next); + Utf8NextCodePoint(this->text_, position, &next); this->DeleteText(TextRange::FromTwoSides(position, next), stop_composition); } // Return the position of deleted character. Index TextHostControlService::DeleteCharPrevious(Index position, bool stop_composition) { - if (!Utf8IsValidInsertPosition(this->text_.data(), this->text_.size(), - position)) { + if (!Utf8IsValidInsertPosition(this->text_, position)) { CRU_LOG_TAG_ERROR("Invalid text delete position {}.", position); return 0; } if (position == 0) return 0; Index previous; - Utf8PreviousCodePoint(this->text_.data(), this->text_.size(), position, - &previous); + Utf8PreviousCodePoint(this->text_, position, &previous); this->DeleteText(TextRange::FromTwoSides(previous, position), stop_composition); return previous; @@ -270,14 +264,12 @@ void TextHostControlService::DeleteText(TextRange range, bool stop_composition) { if (range.count == 0) return; range = range.Normalize(); - if (!Utf8IsValidInsertPosition(this->text_.data(), this->text_.size(), - range.GetStart())) { + if (!Utf8IsValidInsertPosition(this->text_, range.GetStart())) { CRU_LOG_TAG_ERROR("Invalid text delete start position {}.", range.GetStart()); return; } - if (!Utf8IsValidInsertPosition(this->text_.data(), this->text_.size(), - range.GetEnd())) { + if (!Utf8IsValidInsertPosition(this->text_, range.GetEnd())) { CRU_LOG_TAG_ERROR("Invalid text delete end position {}.", range.GetEnd()); return; } |
