From 3c8d5c8f732239a8b50418be27464e30b9dddeae Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 17 Oct 2025 08:37:30 +0800 Subject: Exception remove string. --- include/cru/base/Exception.h | 23 +---------------------- include/cru/base/Format.h | 2 +- include/cru/base/SubProcess.h | 15 +++++++-------- include/cru/base/io/Stream.h | 11 ++--------- include/cru/platform/Check.h | 30 ------------------------------ include/cru/platform/Exception.h | 17 ----------------- include/cru/ui/ThemeManager.h | 2 +- include/cru/ui/ThemeResourceDictionary.h | 4 ++-- include/cru/ui/mapper/Mapper.h | 6 +++--- 9 files changed, 17 insertions(+), 93 deletions(-) (limited to 'include/cru') diff --git a/include/cru/base/Exception.h b/include/cru/base/Exception.h index f42406e0..e4da91f5 100644 --- a/include/cru/base/Exception.h +++ b/include/cru/base/Exception.h @@ -1,5 +1,5 @@ #pragma once -#include "String.h" +#include "Base.h" #include #include @@ -13,16 +13,10 @@ class CRU_BASE_API Exception : public std::exception { public: explicit Exception(std::string message = "", std::shared_ptr inner = nullptr); - explicit Exception(StringView message, - std::shared_ptr inner = nullptr); ~Exception() override; public: - [[deprecated("Use GetUtf8Message.")]] String GetMessage() const { - return String::FromUtf8(message_); - } - std::string GetUtf8Message() const { return this->message_; } std::exception* GetInner() const noexcept { return inner_.get(); } @@ -35,16 +29,6 @@ class CRU_BASE_API Exception : public std::exception { void AppendMessage(std::string_view additional_message); void AppendMessage(std::optional additional_message); - [[deprecated("Use void SetMessage(std::string message) instead.")]] - void SetMessage(StringView message); - [[deprecated( - "Use void AppendMessage(std::string_view additional_message) instead.")]] - void AppendMessage(StringView additional_message); - [[deprecated( - "Use void AppendMessage(std::optional " - "additional_message) instead.")]] - void AppendMessage(std::optional additional_message); - private: std::string message_; std::shared_ptr inner_; @@ -71,11 +55,6 @@ class ErrnoException : public Exception { */ explicit ErrnoException(std::string_view message); ErrnoException(std::string_view message, int errno_code); - /** - * @brief will retrieve errno automatically. - */ - explicit ErrnoException(StringView message); - ErrnoException(StringView message, int errno_code); int GetErrnoCode() const { return errno_code_; } diff --git a/include/cru/base/Format.h b/include/cru/base/Format.h index 2d95b2fd..4f56d189 100644 --- a/include/cru/base/Format.h +++ b/include/cru/base/Format.h @@ -128,7 +128,7 @@ void FormatAppendFromFormatTokenList( return; } else { throw Exception( - u"Currently do not support positional or named place holder."); + "Currently do not support positional or named place holder."); } } else { current += token.data; diff --git a/include/cru/base/SubProcess.h b/include/cru/base/SubProcess.h index 482edb6e..1562769e 100644 --- a/include/cru/base/SubProcess.h +++ b/include/cru/base/SubProcess.h @@ -1,7 +1,6 @@ #pragma once #include "Base.h" #include "Exception.h" -#include "String.h" #include "io/Stream.h" #include @@ -48,9 +47,9 @@ class CRU_BASE_API SubProcessInternalException : public SubProcessException { }; struct SubProcessStartInfo { - String program; - std::vector arguments; - std::unordered_map environments; + std::string program; + std::vector arguments; + std::unordered_map environments; }; enum class SubProcessExitType { @@ -216,12 +215,12 @@ class CRU_BASE_API SubProcess : public Object { public: static SubProcess Create( - String program, std::vector arguments = {}, - std::unordered_map environments = {}); + std::string program, std::vector arguments = {}, + std::unordered_map environments = {}); static SubProcessExitResult Call( - String program, std::vector arguments = {}, - std::unordered_map environments = {}); + std::string program, std::vector arguments = {}, + std::unordered_map environments = {}); public: SubProcess(SubProcessStartInfo start_info); diff --git a/include/cru/base/io/Stream.h b/include/cru/base/io/Stream.h index 2f02a8c2..f082b490 100644 --- a/include/cru/base/io/Stream.h +++ b/include/cru/base/io/Stream.h @@ -1,24 +1,17 @@ #pragma once #include "../Base.h" - +#include "../Buffer.h" #include "../Exception.h" -#include "../String.h" #include namespace cru::io { class CRU_BASE_API StreamOperationNotSupportedException : public Exception { public: - explicit StreamOperationNotSupportedException(StringView operation); explicit StreamOperationNotSupportedException(std::string operation); public: - [[deprecated("Use GetOperationUtf8 instead.")]] - String GetOperation() const { - return String::FromUtf8(operation_); - } - std::string GetOperationUtf8() const { return operation_; } public: @@ -101,7 +94,7 @@ class CRU_BASE_API Stream : public Object { virtual Buffer ReadToEnd(Index grow_size = 256); // Utf8 encoding. - String ReadToEndAsUtf8String(); + std::string ReadToEndAsUtf8String(); protected: virtual bool DoCanSeek(); diff --git a/include/cru/platform/Check.h b/include/cru/platform/Check.h index 202ee86e..b36b7fc1 100644 --- a/include/cru/platform/Check.h +++ b/include/cru/platform/Check.h @@ -2,40 +2,10 @@ #include "Exception.h" #include "Resource.h" -#include "cru/base/String.h" - #include #include namespace cru::platform { -template -TTarget* CheckPlatform(IPlatformResource* resource, - const String& target_platform) { - if (resource == nullptr) return nullptr; - const auto result = dynamic_cast(resource); - if (result == nullptr) { - throw PlatformNotMatchException( - resource->GetPlatformId(), target_platform, - u"Try to convert resource to target platform failed."); - } - return result; -} - -template -std::shared_ptr CheckPlatform(const std::shared_ptr& resource, - const String& target_platform) { - if (resource == nullptr) return nullptr; - static_assert(std::is_base_of_v, - "TSource must be a subclass of INativeResource."); - const auto result = std::dynamic_pointer_cast(resource); - if (result == nullptr) { - throw PlatformNotMatchException( - resource->GetPlatformId(), target_platform, - u"Try to convert resource to target platform failed."); - } - return result; -} - template TTarget* CheckPlatform(IPlatformResource* resource, std::string target_platform) { diff --git a/include/cru/platform/Exception.h b/include/cru/platform/Exception.h index f8ed5b0c..f43162d1 100644 --- a/include/cru/platform/Exception.h +++ b/include/cru/platform/Exception.h @@ -16,17 +16,8 @@ class CRU_PLATFORM_API PlatformNotMatchException : public PlatformException { std::string resource_platform, std::string target_platform, std::optional additional_message = std::nullopt); - PlatformNotMatchException( - StringView resource_platform, StringView target_platform, - std::optional additional_message = std::nullopt); - ~PlatformNotMatchException() override; - [[deprecated("Use GetResourcePlatformUtf8 instead.")]] - String GetResourcePlatform() const; - [[deprecated("Use GetTargetPlatform instead.")]] - String GetTargetPlatform() const; - std::string GetResourcePlatformUtf8() const { return resource_platform_; } std::string GetTargetPlatformUtf8() const { return target_platform_; } @@ -52,16 +43,8 @@ class CRU_PLATFORM_API PlatformUnsupportedException : public PlatformException { std::string platform, std::string operation, std::optional additional_message); - PlatformUnsupportedException(StringView platform, StringView operation, - std::optional additional_message); - ~PlatformUnsupportedException() override; - [[deprecated("Use GetPlatformUtf8 instead.")]] - String GetPlatform() const; - [[deprecated("Use GetOperationUtf8 instead.")]] - String GetOperation() const; - std::string GetPlatformUtf8() const { return platform_; } std::string GetOperationUtf8() const { return operation_; } diff --git a/include/cru/ui/ThemeManager.h b/include/cru/ui/ThemeManager.h index f3f01313..72ade899 100644 --- a/include/cru/ui/ThemeManager.h +++ b/include/cru/ui/ThemeManager.h @@ -35,7 +35,7 @@ class CRU_UI_API ThemeManager : public Object { } } throw ThemeResourceKeyNotExistException( - Format(u"Theme resource key {} not exist.", key)); + std::format("Theme resource key {} not exist.", key.ToUtf8())); } String GetResourceString(const String& key); diff --git a/include/cru/ui/ThemeResourceDictionary.h b/include/cru/ui/ThemeResourceDictionary.h index 2ddb4a90..0cbda01b 100644 --- a/include/cru/ui/ThemeResourceDictionary.h +++ b/include/cru/ui/ThemeResourceDictionary.h @@ -2,13 +2,13 @@ #include "Base.h" #include "cru/base/Base.h" -#include "cru/base/Format.h" #include "cru/xml/XmlNode.h" #include "mapper/MapperRegistry.h" #include "style/StyleRuleSet.h" #include #include +#include #include #include @@ -48,7 +48,7 @@ class CRU_UI_API ThemeResourceDictionary : public Object { auto find_result = resource_map_.find(key); if (find_result == resource_map_.cend()) { throw ThemeResourceKeyNotExistException( - Format(u"Theme resource key {} not exist.", key)); + std::format("Theme resource key {} not exist.", key.ToUtf8())); } auto& cache = find_result->second.cache; diff --git a/include/cru/ui/mapper/Mapper.h b/include/cru/ui/mapper/Mapper.h index 40e15186..d391fac3 100644 --- a/include/cru/ui/mapper/Mapper.h +++ b/include/cru/ui/mapper/Mapper.h @@ -66,7 +66,7 @@ class CRU_UI_API BasicMapper : public MapperBase { virtual T MapFromString(String str) { if (!SupportMapFromString()) { - throw Exception(u"This mapper does not support map from string."); + throw Exception("This mapper does not support map from string."); } return DoMapFromString(str); @@ -74,11 +74,11 @@ class CRU_UI_API BasicMapper : public MapperBase { T MapFromXml(xml::XmlElementNode* node) { if (!SupportMapFromXml()) { - throw Exception(u"This mapper does not support map from xml."); + throw Exception("This mapper does not support map from xml."); } if (!XmlElementIsOfThisType(node)) { - throw Exception(u"This xml element is not of mapping type."); + throw Exception("This xml element is not of mapping type."); } return DoMapFromXml(node); -- cgit v1.2.3