diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-09-07 11:46:11 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-09-07 11:46:11 +0800 |
commit | a0403d95bea3e3a3eaedf71a0d9c6d4e1316bd8c (patch) | |
tree | b97687f99055b04775b63b7bafd2c909a7074cdb /src | |
parent | 20123151d12a0b01453ab6a36c84e4d3e5ea9504 (diff) | |
download | cru-a0403d95bea3e3a3eaedf71a0d9c6d4e1316bd8c.tar.gz cru-a0403d95bea3e3a3eaedf71a0d9c6d4e1316bd8c.tar.bz2 cru-a0403d95bea3e3a3eaedf71a0d9c6d4e1316bd8c.zip |
Use std::string in logger.
Diffstat (limited to 'src')
23 files changed, 122 insertions, 115 deletions
diff --git a/src/base/log/Logger.cpp b/src/base/log/Logger.cpp index 8aa8915c..c195cd87 100644 --- a/src/base/log/Logger.cpp +++ b/src/base/log/Logger.cpp @@ -3,6 +3,7 @@ #include <algorithm> #include <ctime> +#include <format> #ifdef CRU_PLATFORM_WINDOWS #include "cru/base/platform/win/DebugLogTarget.h" @@ -35,32 +36,32 @@ void Logger::RemoveLogTarget(ILogTarget *target) { } namespace { -String LogLevelToString(LogLevel level) { +const char *LogLevelToString(LogLevel level) { switch (level) { case LogLevel::Debug: - return u"DEBUG"; + return "DEBUG"; case LogLevel::Info: - return u"INFO"; + return "INFO"; case LogLevel::Warn: - return u"WARN"; + return "WARN"; case LogLevel::Error: - return u"ERROR"; + return "ERROR"; default: std::terminate(); } } -String GetLogTime() { +std::string GetLogTime() { auto time = std::time(nullptr); auto calendar = std::localtime(&time); - return Format(u"{}:{}:{}", calendar->tm_hour, calendar->tm_min, - calendar->tm_sec); + return std::format("{}:{}:{}", calendar->tm_hour, calendar->tm_min, + calendar->tm_sec); } -String MakeLogFinalMessage(const LogInfo &log_info) { - return Format(u"[{}] {} {}: {}\n", GetLogTime(), - LogLevelToString(log_info.level), log_info.tag, - log_info.message); +std::string MakeLogFinalMessage(const LogInfo &log_info) { + return std::format("[{}] {} {}: {}\n", GetLogTime(), + LogLevelToString(log_info.level), log_info.tag, + log_info.message); } } // namespace @@ -86,18 +87,19 @@ void Logger::Log(LogInfo log_info) { log_queue_.Push(std::move(log_info)); } -LoggerCppStream::LoggerCppStream(Logger *logger, LogLevel level, String tag) +LoggerCppStream::LoggerCppStream(Logger *logger, LogLevel level, + std::string tag) : logger_(logger), level_(level), tag_(std::move(tag)) {} LoggerCppStream LoggerCppStream::WithLevel(LogLevel level) const { return LoggerCppStream(this->logger_, level, this->tag_); } -LoggerCppStream LoggerCppStream::WithTag(String tag) const { +LoggerCppStream LoggerCppStream::WithTag(std::string tag) const { return LoggerCppStream(this->logger_, this->level_, std::move(tag)); } -void LoggerCppStream::Consume(StringView str) { - this->logger_->Log(this->level_, this->tag_, str.ToString()); +void LoggerCppStream::Consume(std::string_view str) { + this->logger_->Log(this->level_, this->tag_, std::string(str)); } } // namespace cru::log diff --git a/src/base/log/StdioLogTarget.cpp b/src/base/log/StdioLogTarget.cpp index 64ddcacc..45203f2c 100644 --- a/src/base/log/StdioLogTarget.cpp +++ b/src/base/log/StdioLogTarget.cpp @@ -7,20 +7,19 @@ StdioLogTarget::StdioLogTarget() {} StdioLogTarget::~StdioLogTarget() {} -void StdioLogTarget::Write(log::LogLevel level, StringView s) { +void StdioLogTarget::Write(log::LogLevel level, std::string message) { #ifdef CRU_PLATFORM_WINDOWS + String s = String::FromUtf8(message); if (level == log::LogLevel::Error) { std::wcerr.write(reinterpret_cast<const wchar_t*>(s.data()), s.size()); } else { std::wcout.write(reinterpret_cast<const wchar_t*>(s.data()), s.size()); } #else - std::string m = s.ToUtf8(); - if (level == log::LogLevel::Error) { - std::cerr << m; + std::cerr << message; } else { - std::cout << m; + std::cout << message; } #endif } diff --git a/src/base/platform/unix/PosixSpawnSubProcess.cpp b/src/base/platform/unix/PosixSpawnSubProcess.cpp index f7d2e855..f99d3224 100644 --- a/src/base/platform/unix/PosixSpawnSubProcess.cpp +++ b/src/base/platform/unix/PosixSpawnSubProcess.cpp @@ -145,14 +145,14 @@ SubProcessExitResult PosixSpawnSubProcessImpl::PlatformWaitForProcess() { while (waitpid(pid_, &wstatus, 0) == -1) { if (errno == EINTR) { - CRU_LOG_TAG_INFO(u"Waitpid is interrupted by a signal. Call it again."); + CRU_LOG_TAG_INFO("Waitpid is interrupted by a signal. Call it again."); continue; } std::unique_ptr<ErrnoException> inner(new ErrnoException(errno)); - throw SubProcessInternalException( - u"Failed to call waitpid on a subprocess.", std::move(inner)); + throw SubProcessInternalException("Failed to call waitpid on a subprocess.", + std::move(inner)); } if (WIFEXITED(wstatus)) { diff --git a/src/base/platform/unix/UnixFile.cpp b/src/base/platform/unix/UnixFile.cpp index 9d4db949..00ed3b9c 100644 --- a/src/base/platform/unix/UnixFile.cpp +++ b/src/base/platform/unix/UnixFile.cpp @@ -19,10 +19,10 @@ UnixFileDescriptor::UnixFileDescriptor(int descriptor, bool auto_close, close_(std::move(close)) {} UnixFileDescriptor::~UnixFileDescriptor() { - constexpr auto kLogTag = u"cru::platform::unix::UnixFileDescriptor"; + constexpr auto kLogTag = "cru::platform::unix::UnixFileDescriptor"; if (this->IsValid() && this->IsAutoClose()) { if (!this->DoClose()) { - CRU_LOG_TAG_ERROR(u"Failed to close file descriptor {}, errno {}.", + CRU_LOG_TAG_ERROR("Failed to close file descriptor {}, errno {}.", descriptor_, errno); } } diff --git a/src/platform/graphics/direct2d/Painter.cpp b/src/platform/graphics/direct2d/Painter.cpp index ec96080a..a505e46e 100644 --- a/src/platform/graphics/direct2d/Painter.cpp +++ b/src/platform/graphics/direct2d/Painter.cpp @@ -22,7 +22,7 @@ D2DDeviceContextPainter::D2DDeviceContextPainter( D2DDeviceContextPainter::~D2DDeviceContextPainter() { if (is_drawing_) { - CRU_LOG_TAG_INFO(u"You may forget to call EndDraw before destroying painter."); + CRU_LOG_TAG_INFO("You may forget to call EndDraw before destroying painter."); } if (release_) { diff --git a/src/platform/gui/osx/Clipboard.mm b/src/platform/gui/osx/Clipboard.mm index db5f6ed3..d87ab7e3 100644 --- a/src/platform/gui/osx/Clipboard.mm +++ b/src/platform/gui/osx/Clipboard.mm @@ -25,7 +25,7 @@ OsxClipboardPrivate::~OsxClipboardPrivate() {} String OsxClipboardPrivate::GetText() { auto result = [pasteboard_ readObjectsForClasses:@[ NSString.class ] options:nil]; if (result == nil) { - CRU_LOG_TAG_WARN(u"Failed to get text from clipboard"); + CRU_LOG_TAG_WARN("Failed to get text from clipboard"); return u""; } else { if (result.count == 0) { diff --git a/src/platform/gui/osx/ClipboardPrivate.h b/src/platform/gui/osx/ClipboardPrivate.h index 766026b6..41554297 100644 --- a/src/platform/gui/osx/ClipboardPrivate.h +++ b/src/platform/gui/osx/ClipboardPrivate.h @@ -7,7 +7,7 @@ namespace cru::platform::gui::osx { namespace details { class OsxClipboardPrivate : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"OsxClipboardPrivate") + CRU_DEFINE_CLASS_LOG_TAG("OsxClipboardPrivate") public: explicit OsxClipboardPrivate(NSPasteboard* pasteboard); diff --git a/src/platform/gui/win/Clipboard.cpp b/src/platform/gui/win/Clipboard.cpp index 9e305d1c..5525cb40 100644 --- a/src/platform/gui/win/Clipboard.cpp +++ b/src/platform/gui/win/Clipboard.cpp @@ -13,25 +13,25 @@ String WinClipboard::GetText() { auto god_window = application_->GetGodWindow(); if (!::OpenClipboard(god_window->GetHandle())) { - CRU_LOG_TAG_WARN(u"Failed to open clipboard."); + CRU_LOG_TAG_WARN("Failed to open clipboard."); return {}; } if (!::IsClipboardFormatAvailable(CF_UNICODETEXT)) { - CRU_LOG_TAG_WARN(u"Clipboard format for text is not available."); + CRU_LOG_TAG_WARN("Clipboard format for text is not available."); return {}; } auto handle = ::GetClipboardData(CF_UNICODETEXT); if (handle == nullptr) { - CRU_LOG_TAG_WARN(u"Failed to get clipboard data."); + CRU_LOG_TAG_WARN("Failed to get clipboard data."); return {}; } auto ptr = ::GlobalLock(handle); if (ptr == nullptr) { - CRU_LOG_TAG_WARN(u"Failed to lock clipboard data."); + CRU_LOG_TAG_WARN("Failed to lock clipboard data."); ::CloseClipboard(); return {}; } @@ -48,21 +48,21 @@ void WinClipboard::SetText(String text) { auto god_window = application_->GetGodWindow(); if (!::OpenClipboard(god_window->GetHandle())) { - CRU_LOG_TAG_WARN(u"Failed to open clipboard."); + CRU_LOG_TAG_WARN("Failed to open clipboard."); return; } auto handle = GlobalAlloc(GMEM_MOVEABLE, (text.size() + 1) * sizeof(wchar_t)); if (handle == nullptr) { - CRU_LOG_TAG_WARN(u"Failed to allocate clipboard data."); + CRU_LOG_TAG_WARN("Failed to allocate clipboard data."); ::CloseClipboard(); return; } auto ptr = ::GlobalLock(handle); if (ptr == nullptr) { - CRU_LOG_TAG_WARN(u"Failed to lock clipboard data."); + CRU_LOG_TAG_WARN("Failed to lock clipboard data."); ::GlobalFree(handle); ::CloseClipboard(); return; @@ -73,7 +73,7 @@ void WinClipboard::SetText(String text) { ::GlobalUnlock(handle); if (::SetClipboardData(CF_UNICODETEXT, handle) == nullptr) { - CRU_LOG_TAG_WARN(u"Failed to set clipboard data."); + CRU_LOG_TAG_WARN("Failed to set clipboard data."); } ::CloseClipboard(); diff --git a/src/platform/gui/win/Cursor.cpp b/src/platform/gui/win/Cursor.cpp index e6cce5b9..24e9c2fc 100644 --- a/src/platform/gui/win/Cursor.cpp +++ b/src/platform/gui/win/Cursor.cpp @@ -16,7 +16,7 @@ WinCursor::~WinCursor() { if (!::DestroyCursor(handle_)) { // This is not a fetal error but might still need notice because it may // cause leak. - CRU_LOG_TAG_WARN(u"Failed to destroy a cursor. Last error code: {}", + CRU_LOG_TAG_WARN("Failed to destroy a cursor. Last error code: {}", ::GetLastError()); } } diff --git a/src/platform/gui/win/GodWindow.cpp b/src/platform/gui/win/GodWindow.cpp index c969df8f..485eae72 100644 --- a/src/platform/gui/win/GodWindow.cpp +++ b/src/platform/gui/win/GodWindow.cpp @@ -43,7 +43,7 @@ GodWindow::GodWindow(WinUiApplication* application) { GodWindow::~GodWindow() { if (!::DestroyWindow(hwnd_)) { // Although this could be "safely" ignore. - CRU_LOG_TAG_WARN(u"Failed to destroy god window."); + CRU_LOG_TAG_WARN("Failed to destroy god window."); } } diff --git a/src/platform/gui/win/InputMethod.cpp b/src/platform/gui/win/InputMethod.cpp index 306dc3fa..94795c8c 100644 --- a/src/platform/gui/win/InputMethod.cpp +++ b/src/platform/gui/win/InputMethod.cpp @@ -35,7 +35,7 @@ AutoHIMC& AutoHIMC::operator=(AutoHIMC&& other) { AutoHIMC::~AutoHIMC() { if (handle_) { if (!::ImmReleaseContext(hwnd_, handle_)) - CRU_LOG_TAG_WARN(u"Failed to release HIMC."); + CRU_LOG_TAG_WARN("Failed to release HIMC."); } } @@ -156,7 +156,7 @@ WinInputMethodContext::~WinInputMethodContext() {} void WinInputMethodContext::EnableIME() { const auto hwnd = native_window_->GetWindowHandle(); if (::ImmAssociateContextEx(hwnd, nullptr, IACE_DEFAULT) == FALSE) { - CRU_LOG_TAG_WARN(u"Failed to enable ime."); + CRU_LOG_TAG_WARN("Failed to enable ime."); } } @@ -167,21 +167,21 @@ void WinInputMethodContext::DisableIME() { ::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0); if (::ImmAssociateContextEx(hwnd, nullptr, 0) == FALSE) { - CRU_LOG_TAG_WARN(u"Failed to disable ime."); + CRU_LOG_TAG_WARN("Failed to disable ime."); } } void WinInputMethodContext::CompleteComposition() { auto himc = GetHIMC(); if (!::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0)) { - CRU_LOG_TAG_WARN(u"Failed to complete composition."); + CRU_LOG_TAG_WARN("Failed to complete composition."); } } void WinInputMethodContext::CancelComposition() { auto himc = GetHIMC(); if (!::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_CANCEL, 0)) { - CRU_LOG_TAG_WARN(u"Failed to complete composition."); + CRU_LOG_TAG_WARN("Failed to complete composition."); } } @@ -200,7 +200,7 @@ void WinInputMethodContext::SetCandidateWindowPosition(const Point& point) { form.ptCurrentPos = native_window_->DipToPixel(point); if (!::ImmSetCandidateWindow(himc.Get(), &form)) - CRU_LOG_TAG_DEBUG(u"Failed to set input method candidate window position."); + CRU_LOG_TAG_DEBUG("Failed to set input method candidate window position."); } IEvent<std::nullptr_t>* WinInputMethodContext::CompositionStartEvent() { @@ -228,8 +228,8 @@ void WinInputMethodContext::OnWindowNativeMessage( // should only trigger ascci character. If it is a charater from // supplementary planes, it should be handled with ime messages. CRU_LOG_TAG_WARN( - u"A WM_CHAR message for character from supplementary " - u"planes is ignored."); + "A WM_CHAR message for character from supplementary " + "planes is ignored."); } else { if (c != '\b') { // ignore backspace if (c == '\r') c = '\n'; // Change \r to \n @@ -245,8 +245,8 @@ void WinInputMethodContext::OnWindowNativeMessage( composition_event_.Raise(nullptr); auto composition_text = GetCompositionText(); if constexpr (DebugFlags::input_method) { - CRU_LOG_TAG_DEBUG(u"WM_IME_COMPOSITION composition text:\n{}", - composition_text); + CRU_LOG_TAG_DEBUG("WM_IME_COMPOSITION composition text:\n{}", + composition_text); } if (message.l_param & GCS_RESULTSTR) { auto result_string = GetResultString(); @@ -256,14 +256,14 @@ void WinInputMethodContext::OnWindowNativeMessage( } case WM_IME_STARTCOMPOSITION: { if constexpr (DebugFlags::input_method) { - CRU_LOG_TAG_DEBUG(u"WM_IME_STARTCOMPOSITION received."); + CRU_LOG_TAG_DEBUG("WM_IME_STARTCOMPOSITION received."); } composition_start_event_.Raise(nullptr); break; } case WM_IME_ENDCOMPOSITION: { if constexpr (DebugFlags::input_method) { - CRU_LOG_TAG_DEBUG(u"WM_IME_ENDCOMPOSITION received."); + CRU_LOG_TAG_DEBUG("WM_IME_ENDCOMPOSITION received."); } composition_end_event_.Raise(nullptr); break; diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp index 690e56de..5bd14323 100644 --- a/src/platform/gui/win/Window.cpp +++ b/src/platform/gui/win/Window.cpp @@ -207,7 +207,7 @@ bool WinNativeWindow::ReleaseMouse() { void WinNativeWindow::RequestRepaint() { if constexpr (DebugFlags::paint) { - CRU_LOG_TAG_DEBUG(u"A repaint is requested."); + CRU_LOG_TAG_DEBUG("A repaint is requested."); } if (!::InvalidateRect(hwnd_, nullptr, FALSE)) throw Win32Error(::GetLastError(), u"Failed to invalidate window."); @@ -235,8 +235,8 @@ void WinNativeWindow::SetCursor(std::shared_ptr<ICursor> cursor) { if (!::SetClassLongPtrW(hwnd_, GCLP_HCURSOR, reinterpret_cast<LONG_PTR>(cursor_->GetHandle()))) { CRU_LOG_TAG_WARN( - u"Failed to set cursor because failed to set class long. Last " - u"error code: {}.", + "Failed to set cursor because failed to set class long. Last " + "error code: {}.", ::GetLastError()); return; } @@ -477,7 +477,7 @@ void WinNativeWindow::RecreateWindow() { if (dpi == 0) throw Win32Error(::GetLastError(), u"Failed to get dpi of window."); dpi_ = static_cast<float>(dpi); - CRU_LOG_TAG_DEBUG(u"Dpi of window is {}.", dpi_); + CRU_LOG_TAG_DEBUG("Dpi of window is {}.", dpi_); window_manager->RegisterWindow(hwnd_, this); @@ -507,7 +507,7 @@ void WinNativeWindow::OnPaintInternal() { paint_event_.Raise(nullptr); ValidateRect(hwnd_, nullptr); if constexpr (DebugFlags::paint) { - CRU_LOG_TAG_DEBUG(u"A repaint is finished."); + CRU_LOG_TAG_DEBUG("A repaint is finished."); } } diff --git a/src/ui/ThemeResourceDictionary.cpp b/src/ui/ThemeResourceDictionary.cpp index fff25e09..421723f5 100644 --- a/src/ui/ThemeResourceDictionary.cpp +++ b/src/ui/ThemeResourceDictionary.cpp @@ -47,10 +47,11 @@ void ThemeResourceDictionary::UpdateResourceMap(xml::XmlElementNode* xml_root) { resource_map_[entry.name] = std::move(entry); } else { - CRU_LOG_TAG_DEBUG(u"Ignore unknown element {} of theme.", c->GetTag()); + CRU_LOG_TAG_DEBUG("Ignore unknown element {} of theme.", + c->GetTag().ToUtf8()); } } else { - CRU_LOG_TAG_DEBUG(u"Ignore text or comment node of theme."); + CRU_LOG_TAG_DEBUG("Ignore text or comment node of theme."); } } } diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp index d6770684..3218f185 100644 --- a/src/ui/controls/Control.cpp +++ b/src/ui/controls/Control.cpp @@ -31,7 +31,7 @@ Control::Control() { Control::~Control() { if (host::WindowHost::IsInEventHandling()) { CRU_LOG_TAG_ERROR( - u"Control destroyed during event handling. Please use DeleteLater."); + "Control destroyed during event handling. Please use DeleteLater."); } in_destruction_ = true; diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp index bc562e88..ace02a46 100644 --- a/src/ui/controls/TextHostControlService.cpp +++ b/src/ui/controls/TextHostControlService.cpp @@ -227,7 +227,7 @@ void TextHostControlService::SetText(String text, bool stop_composition) { void TextHostControlService::InsertText(Index position, StringView text, bool stop_composition) { if (!Utf16IsValidInsertPosition(this->text_, position)) { - CRU_LOG_TAG_ERROR(u"Invalid text insert position."); + CRU_LOG_TAG_ERROR("Invalid text insert position."); return; } this->text_.insert(this->text_.cbegin() + position, text); @@ -240,7 +240,7 @@ void TextHostControlService::InsertText(Index position, StringView text, void TextHostControlService::DeleteChar(Index position, bool stop_composition) { if (!Utf16IsValidInsertPosition(this->text_, position)) { - CRU_LOG_TAG_ERROR(u"Invalid text delete position."); + CRU_LOG_TAG_ERROR("Invalid text delete position."); return; } if (position == static_cast<Index>(this->text_.size())) return; @@ -253,7 +253,7 @@ void TextHostControlService::DeleteChar(Index position, bool stop_composition) { Index TextHostControlService::DeleteCharPrevious(Index position, bool stop_composition) { if (!Utf16IsValidInsertPosition(this->text_, position)) { - CRU_LOG_TAG_ERROR(u"Invalid text delete position."); + CRU_LOG_TAG_ERROR("Invalid text delete position."); return 0; } if (position == 0) return 0; @@ -269,11 +269,11 @@ void TextHostControlService::DeleteText(TextRange range, if (range.count == 0) return; range = range.Normalize(); if (!Utf16IsValidInsertPosition(this->text_, range.GetStart())) { - CRU_LOG_TAG_ERROR(u"Invalid text delete start position."); + CRU_LOG_TAG_ERROR("Invalid text delete start position."); return; } if (!Utf16IsValidInsertPosition(this->text_, range.GetStart())) { - CRU_LOG_TAG_ERROR(u"Invalid text delete end position."); + CRU_LOG_TAG_ERROR("Invalid text delete end position."); return; } this->text_.erase(this->text_.cbegin() + range.GetStart(), @@ -465,7 +465,7 @@ void TextHostControlService::UpdateInputMethodPosition() { right_bottom.y += 5; if constexpr (debug_flags::text_service) { - CRU_LOG_TAG_DEBUG(u"Calculate input method candidate window position: {}.", + CRU_LOG_TAG_DEBUG("Calculate input method candidate window position: {}.", right_bottom); } diff --git a/src/ui/helper/ClickDetector.cpp b/src/ui/helper/ClickDetector.cpp index b7e800a8..2e3dc1a0 100644 --- a/src/ui/helper/ClickDetector.cpp +++ b/src/ui/helper/ClickDetector.cpp @@ -58,7 +58,7 @@ ClickDetector::ClickDetector(controls::Control* control) { this->state_ == ClickState::Hover) { if (!this->control_->CaptureMouse()) { if constexpr (debug_flags::click_detector) { - CRU_LOG_TAG_DEBUG(u"Failed to capture mouse when begin click."); + CRU_LOG_TAG_DEBUG("Failed to capture mouse when begin click."); } return; } @@ -137,7 +137,7 @@ void ClickDetector::SetState(ClickState state) { UnreachableCode(); } }; - CRU_LOG_TAG_DEBUG(u"Click state changed, new state: {}.", to_string(state)); + CRU_LOG_TAG_DEBUG("Click state changed, new state: {}.", to_string(state)); } state_ = state; diff --git a/src/ui/helper/ShortcutHub.cpp b/src/ui/helper/ShortcutHub.cpp index c413ab2a..e3a06e8c 100644 --- a/src/ui/helper/ShortcutHub.cpp +++ b/src/ui/helper/ShortcutHub.cpp @@ -64,7 +64,7 @@ const std::vector<ShortcutInfo>& ShortcutHub::GetShortcutByKeyBind( void ShortcutHub::Install(controls::Control* control) { if (!event_guard_.IsEmpty()) { - CRU_LOG_TAG_ERROR(u"Shortcut hub is already installed. Failed to install."); + CRU_LOG_TAG_ERROR("Shortcut hub is already installed. Failed to install."); return; } @@ -74,7 +74,7 @@ void ShortcutHub::Install(controls::Control* control) { void ShortcutHub::Uninstall() { if (event_guard_.IsEmpty()) { - CRU_LOG_TAG_WARN(u"Shortcut hub is not installed. Failed to uninstall."); + CRU_LOG_TAG_WARN("Shortcut hub is not installed. Failed to uninstall."); return; } @@ -89,17 +89,18 @@ void ShortcutHub::OnKeyDown(events::KeyEventArgs& event) { if constexpr (debug_flags::shortcut) { if (shortcut_list.empty()) { - CRU_LOG_TAG_DEBUG(u"No shortcut for key bind {}.", key_bind.ToString()); + CRU_LOG_TAG_DEBUG("No shortcut for key bind {}.", + key_bind.ToString().ToUtf8()); } - CRU_LOG_TAG_DEBUG(u"Begin to handle shortcut for key bind {}.", - key_bind.ToString()); + CRU_LOG_TAG_DEBUG("Begin to handle shortcut for key bind {}.", + key_bind.ToString()); } for (const auto& shortcut : shortcut_list) { auto is_handled = shortcut.handler(); if (is_handled) { if constexpr (debug_flags::shortcut) { - CRU_LOG_TAG_DEBUG(u"Handle {} handled it.", shortcut.name); + CRU_LOG_TAG_DEBUG("Handle {} handled it.", shortcut.name.ToUtf8()); } handled = true; @@ -108,23 +109,24 @@ void ShortcutHub::OnKeyDown(events::KeyEventArgs& event) { break; } else { if constexpr (debug_flags::shortcut) { - CRU_LOG_TAG_DEBUG(u"Handle {} didn't handle it.", shortcut.name); + CRU_LOG_TAG_DEBUG("Handle {} didn't handle it.", + shortcut.name.ToUtf8()); } } } if constexpr (debug_flags::shortcut) { if (!shortcut_list.empty()) { - CRU_LOG_TAG_DEBUG(u"End handling shortcut for key bind {}.", - key_bind.ToString()); + CRU_LOG_TAG_DEBUG("End handling shortcut for key bind {}.", + key_bind.ToString().ToUtf8()); } } if (!handled) { if constexpr (debug_flags::shortcut) { CRU_LOG_TAG_DEBUG( - u"Raise fallback event for unhandled shortcut of key bind {}.", - key_bind.ToString()); + "Raise fallback event for unhandled shortcut of key bind {}.", + key_bind.ToString().ToUtf8()); } fallback_event_.Raise(event); } diff --git a/src/ui/host/RoutedEventDispatch.h b/src/ui/host/RoutedEventDispatch.h index 6677deea..4efc9208 100644 --- a/src/ui/host/RoutedEventDispatch.h +++ b/src/ui/host/RoutedEventDispatch.h @@ -26,7 +26,7 @@ void DispatchEvent( const String& event_name, controls::Control* const original_sender, events::RoutedEvent<EventArgs>* (controls::Control::*event_ptr)(), controls::Control* const last_receiver, Args&&... args) { - constexpr auto kLogTag = u"DispatchEvent"; + constexpr auto kLogTag = "DispatchEvent"; if (original_sender == nullptr) return; @@ -35,9 +35,9 @@ void DispatchEvent( if (original_sender == last_receiver) { if constexpr (debug_flags::routed_event) CRU_LOG_TAG_DEBUG( - u"Routed event {} no need to dispatch (original_sender == " + "Routed event {} no need to dispatch (original_sender == " "last_receiver). Original sender is {}.", - event_name, original_sender->GetControlType()); + event_name.ToUtf8(), original_sender->GetControlType().ToUtf8()); return; } @@ -54,16 +54,16 @@ void DispatchEvent( } if constexpr (debug_flags::routed_event) { - String log = u"Dispatch routed event "; - log += event_name; - log += u". Path (parent first): "; + std::string log = "Dispatch routed event "; + log += event_name.ToUtf8(); + log += ". Path (parent first): "; auto i = receive_list.crbegin(); const auto end = --receive_list.crend(); for (; i != end; ++i) { - log += i->Resolve()->GetControlType(); - log += u" -> "; + log += i->Resolve()->GetControlType().ToUtf8(); + log += " -> "; } - log += i->Resolve()->GetControlType(); + log += i->Resolve()->GetControlType().ToUtf8(); CRU_LOG_TAG_DEBUG(log); } @@ -83,8 +83,8 @@ void DispatchEvent( handled = true; if constexpr (debug_flags::routed_event) CRU_LOG_TAG_DEBUG( - u"Routed event is short-circuit in TUNNEL at {}-st control (count " - u"from parent).", + "Routed event is short-circuit in TUNNEL at {}-st control (count " + "from parent).", count); break; } @@ -103,8 +103,8 @@ void DispatchEvent( if (event_args.IsHandled()) { if constexpr (debug_flags::routed_event) CRU_LOG_TAG_DEBUG( - u"Routed event is short-circuit in BUBBLE at {}-st control " - u"(count from parent).", + "Routed event is short-circuit in BUBBLE at {}-st control " + "(count from parent).", count); break; } @@ -121,7 +121,7 @@ void DispatchEvent( } if constexpr (debug_flags::routed_event) - CRU_LOG_TAG_DEBUG(u"Routed event dispatch finished."); + CRU_LOG_TAG_DEBUG("Routed event dispatch finished."); WindowHost::LeaveEventHandling(); } diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp index 9d0e2006..59e383c5 100644 --- a/src/ui/host/WindowHost.cpp +++ b/src/ui/host/WindowHost.cpp @@ -202,7 +202,7 @@ void WindowHost::RelayoutWithSize(const Size& available_size, for (auto& action : after_layout_stable_action_) action(); after_layout_event_.Raise(AfterLayoutEventArgs{}); after_layout_stable_action_.clear(); - if constexpr (debug_flags::layout) CRU_LOG_TAG_DEBUG(u"A relayout is finished."); + if constexpr (debug_flags::layout) CRU_LOG_TAG_DEBUG("A relayout is finished."); } void WindowHost::Repaint() { diff --git a/src/ui/render/BorderRenderObject.cpp b/src/ui/render/BorderRenderObject.cpp index 0e97c5e8..03fdff24 100644 --- a/src/ui/render/BorderRenderObject.cpp +++ b/src/ui/render/BorderRenderObject.cpp @@ -82,11 +82,13 @@ RenderObject* BorderRenderObject::HitTest(const Point& point) { void BorderRenderObject::Draw(platform::graphics::IPainter* painter) { if constexpr (debug_flags::draw) { CRU_LOG_TAG_DEBUG( - u"BorderRenderObject draw, background: {}, foreground: {}.", - background_brush_ == nullptr ? u"NONE" - : background_brush_->GetDebugString(), - foreground_brush_ == nullptr ? u"NONE" - : foreground_brush_->GetDebugString()); + "BorderRenderObject draw, background: {}, foreground: {}.", + background_brush_ == nullptr + ? "NONE" + : background_brush_->GetDebugString().ToUtf8(), + foreground_brush_ == nullptr + ? "NONE" + : foreground_brush_->GetDebugString().ToUtf8()); } if (background_brush_ != nullptr) @@ -95,7 +97,7 @@ void BorderRenderObject::Draw(platform::graphics::IPainter* painter) { if (is_border_enabled_) { if (border_brush_ == nullptr) { - CRU_LOG_TAG_WARN(u"Border is enabled but border brush is null."); + CRU_LOG_TAG_WARN("Border is enabled but border brush is null."); } else { painter->FillGeometry(geometry_.get(), border_brush_.get()); } diff --git a/src/ui/render/FlexLayoutRenderObject.cpp b/src/ui/render/FlexLayoutRenderObject.cpp index 588c379b..efc98602 100644 --- a/src/ui/render/FlexLayoutRenderObject.cpp +++ b/src/ui/render/FlexLayoutRenderObject.cpp @@ -90,7 +90,7 @@ Size FlexLayoutMeasureContentImpl( const MeasureRequirement& requirement, const MeasureSize& preferred_size, const std::vector<RenderObject*>& children, const std::vector<FlexChildLayoutData>& layout_data, - Alignment item_cross_align, String kLogTag) { + Alignment item_cross_align, std::string kLogTag) { Expects(children.size() == layout_data.size()); direction_tag_t direction_tag; @@ -301,7 +301,7 @@ Size FlexLayoutMeasureContentImpl( if (max_main_length.IsSpecified() && total_length > max_main_length.GetLengthOrUndefined()) { CRU_LOG_TAG_WARN( - u"(Measure) Children's main axis length exceeds required max length."); + "(Measure) Children's main axis length exceeds required max length."); total_length = max_main_length.GetLengthOrUndefined(); } else if (min_main_length.IsSpecified() && total_length < min_main_length.GetLengthOrUndefined()) { diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp index b3a28d6d..1803a131 100644 --- a/src/ui/render/RenderObject.cpp +++ b/src/ui/render/RenderObject.cpp @@ -119,16 +119,16 @@ void RenderObject::Measure(const MeasureRequirement& requirement, preferred_size.OverrideBy(preferred_size_); if constexpr (cru::ui::debug_flags::layout) { - CRU_LOG_TAG_DEBUG(u"{} Measure begins :\nrequirement: {}\npreferred size: {}", - this->GetDebugPathInTree(), requirement.ToDebugString(), - preferred_size.ToDebugString()); + CRU_LOG_TAG_DEBUG("{} Measure begins :\nrequirement: {}\npreferred size: {}", + this->GetDebugPathInTree().ToUtf8(), requirement.ToDebugString().ToUtf8(), + preferred_size.ToDebugString().ToUtf8()); } desired_size_ = OnMeasureCore(merged_requirement, merged_preferred_size); if constexpr (cru::ui::debug_flags::layout) { - CRU_LOG_TAG_DEBUG(u"{} Measure ends :\nresult size: {}", - this->GetDebugPathInTree(), desired_size_); + CRU_LOG_TAG_DEBUG("{} Measure ends :\nresult size: {}", + this->GetDebugPathInTree().ToUtf8(), desired_size_); } Ensures(desired_size_.width >= 0); @@ -144,8 +144,8 @@ Size RenderObject::Measure1(const BoxConstraint& constraint) { void RenderObject::Layout(const Point& offset) { if constexpr (cru::ui::debug_flags::layout) { - CRU_LOG_TAG_DEBUG(u"{} Layout :\noffset: {} size: {}", - this->GetDebugPathInTree(), offset, desired_size_); + CRU_LOG_TAG_DEBUG("{} Layout :\noffset: {} size: {}", + this->GetDebugPathInTree().ToUtf8(), offset, desired_size_); } offset_ = offset; size_ = desired_size_; @@ -192,14 +192,14 @@ Size RenderObject::OnMeasureCore1(const BoxConstraint& constraint) { if (space_size.width > merged_constraint.max.width) { space_size.width = merged_constraint.max.width; - CRU_LOG_TAG_WARN(u"{} space width is over constraint.max.width", - this->GetDebugPathInTree()); + CRU_LOG_TAG_WARN("{} space width is over constraint.max.width", + this->GetDebugPathInTree().ToUtf8()); } if (space_size.height > merged_constraint.max.height) { space_size.height = merged_constraint.max.height; - CRU_LOG_TAG_WARN(u"{} space height is over constraint.max.height", - this->GetDebugPathInTree()); + CRU_LOG_TAG_WARN("{} space height is over constraint.max.height", + this->GetDebugPathInTree().ToUtf8()); } BoxConstraint content_constraint{merged_constraint.max - space_size, diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp index 8a579041..346b4957 100644 --- a/src/ui/render/TextRenderObject.cpp +++ b/src/ui/render/TextRenderObject.cpp @@ -178,10 +178,11 @@ RenderObject* TextRenderObject::HitTest(const Point& point) { void TextRenderObject::Draw(platform::graphics::IPainter* painter) { if constexpr (debug_flags::draw) { CRU_LOG_TAG_DEBUG( - u"Begin to paint, total_offset: {}, size: {}, text_layout: " - u"{}, brush: {}.", + "Begin to paint, total_offset: {}, size: {}, text_layout: " + "{}, brush: {}.", this->GetTotalOffset(), this->GetDesiredSize(), - this->text_layout_->GetDebugString(), this->brush_->GetDebugString()); + this->text_layout_->GetDebugString().ToUtf8(), + this->brush_->GetDebugString().ToUtf8()); } if (this->selection_range_.has_value()) { |