From 20123151d12a0b01453ab6a36c84e4d3e5ea9504 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Sun, 7 Sep 2025 03:34:56 +0800 Subject: Remove some usage of my format. --- src/platform/Exception.cpp | 61 +++++++++++++++-------- src/platform/graphics/SvgGeometryBuilderMixin.cpp | 2 + src/platform/gui/UiApplication.cpp | 2 + 3 files changed, 43 insertions(+), 22 deletions(-) (limited to 'src/platform') diff --git a/src/platform/Exception.cpp b/src/platform/Exception.cpp index 948345e0..d5ae4702 100644 --- a/src/platform/Exception.cpp +++ b/src/platform/Exception.cpp @@ -1,44 +1,61 @@ #include "cru/platform/Exception.h" -#include "cru/base/Format.h" +#include "cru/base/Exception.h" +#include #include +#include namespace cru::platform { PlatformNotMatchException::PlatformNotMatchException( - String resource_platform, String target_platform, - std::optional additional_message) - : resource_platform_(std::move(resource_platform)), + std::string resource_platform, std::string target_platform, + std::optional additional_message) + : PlatformException(std::format( + "Resource platform '{}' does not match target platform '{}'.", + resource_platform_, target_platform_)), + resource_platform_(std::move(resource_platform)), target_platform_(std::move(target_platform)) { - SetMessage( - Format(u"Resource platform '{}' does not match target platform '{}'.", - resource_platform_, target_platform_)); - AppendMessage(additional_message); } -PlatformNotMatchException::~PlatformNotMatchException() {} +PlatformNotMatchException::PlatformNotMatchException( + StringView resource_platform, StringView target_platform, + std::optional additional_message) + : PlatformNotMatchException( + resource_platform.ToUtf8(), target_platform.ToUtf8(), + additional_message.has_value() + ? std::make_optional(additional_message->ToUtf8()) + : std::nullopt) {} -String PlatformNotMatchException::GetResourcePlatform() const { - return resource_platform_; -} +PlatformNotMatchException::~PlatformNotMatchException() {} -String PlatformNotMatchException::GetTargetPlatform() const { - return target_platform_; +PlatformUnsupportedException::PlatformUnsupportedException( + std::string platform, std::string operation, + std::optional additional_message) + : PlatformException( + std::format("Operation '{}' is not supported on platform '{}'.", + operation, platform)), + platform_(std::move(platform)), + operation_(std::move(operation)) { + AppendMessage(additional_message); } PlatformUnsupportedException::PlatformUnsupportedException( - String platform, String operation, + StringView platform, StringView operation, std::optional additional_message) - : platform_(std::move(platform)), operation_(std::move(operation)) { - SetMessage(Format(u"Operation '{}' is not supported on platform '{}'.", - operation_, platform_)); - AppendMessage(additional_message); -} + : PlatformUnsupportedException( + platform.ToUtf8(), operation.ToUtf8(), + additional_message.has_value() + ? std::make_optional(additional_message->ToUtf8()) + : std::nullopt) {} PlatformUnsupportedException::~PlatformUnsupportedException() {} -String PlatformUnsupportedException::GetPlatform() const { return platform_; } +String PlatformUnsupportedException::GetPlatform() const { + return String::FromUtf8(platform_); +} -String PlatformUnsupportedException::GetOperation() const { return operation_; } +String PlatformUnsupportedException::GetOperation() const { + return String::FromUtf8(operation_); +} } // namespace cru::platform diff --git a/src/platform/graphics/SvgGeometryBuilderMixin.cpp b/src/platform/graphics/SvgGeometryBuilderMixin.cpp index 3f8b48ad..bf5275c5 100644 --- a/src/platform/graphics/SvgGeometryBuilderMixin.cpp +++ b/src/platform/graphics/SvgGeometryBuilderMixin.cpp @@ -1,6 +1,8 @@ #include "cru/platform/graphics/SvgGeometryBuilderMixin.h" #include "cru/platform/Exception.h" +#include "cru/base/Format.h" + namespace cru::platform::graphics { SvgGeometryBuilderMixin::SvgGeometryBuilderMixin() {} diff --git a/src/platform/gui/UiApplication.cpp b/src/platform/gui/UiApplication.cpp index e565ce49..4c6f5e1d 100644 --- a/src/platform/gui/UiApplication.cpp +++ b/src/platform/gui/UiApplication.cpp @@ -1,5 +1,7 @@ #include "cru/platform/gui/UiApplication.h" +#include "cru/base/Exception.h" + namespace cru::platform::gui { IUiApplication* IUiApplication::instance = nullptr; -- cgit v1.2.3