diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-10-17 08:37:30 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-10-17 08:37:30 +0800 |
commit | 3c8d5c8f732239a8b50418be27464e30b9dddeae (patch) | |
tree | 8ffb46c18e48c8463c1fb16fcacf216f296b8a1f /include/cru | |
parent | 37943858b3b260589b5dc222bb5184d2846fb6dc (diff) | |
download | cru-3c8d5c8f732239a8b50418be27464e30b9dddeae.tar.gz cru-3c8d5c8f732239a8b50418be27464e30b9dddeae.tar.bz2 cru-3c8d5c8f732239a8b50418be27464e30b9dddeae.zip |
Exception remove string.
Diffstat (limited to 'include/cru')
-rw-r--r-- | include/cru/base/Exception.h | 23 | ||||
-rw-r--r-- | include/cru/base/Format.h | 2 | ||||
-rw-r--r-- | include/cru/base/SubProcess.h | 15 | ||||
-rw-r--r-- | include/cru/base/io/Stream.h | 11 | ||||
-rw-r--r-- | include/cru/platform/Check.h | 30 | ||||
-rw-r--r-- | include/cru/platform/Exception.h | 17 | ||||
-rw-r--r-- | include/cru/ui/ThemeManager.h | 2 | ||||
-rw-r--r-- | include/cru/ui/ThemeResourceDictionary.h | 4 | ||||
-rw-r--r-- | include/cru/ui/mapper/Mapper.h | 6 |
9 files changed, 17 insertions, 93 deletions
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 <exception> #include <optional> @@ -13,16 +13,10 @@ class CRU_BASE_API Exception : public std::exception { public: explicit Exception(std::string message = "", std::shared_ptr<std::exception> inner = nullptr); - explicit Exception(StringView message, - std::shared_ptr<std::exception> 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<std::string_view> 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<std::string_view> " - "additional_message) instead.")]] - void AppendMessage(std::optional<StringView> additional_message); - private: std::string message_; std::shared_ptr<std::exception> 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 <chrono> @@ -48,9 +47,9 @@ class CRU_BASE_API SubProcessInternalException : public SubProcessException { }; struct SubProcessStartInfo { - String program; - std::vector<String> arguments; - std::unordered_map<String, String> environments; + std::string program; + std::vector<std::string> arguments; + std::unordered_map<std::string, std::string> environments; }; enum class SubProcessExitType { @@ -216,12 +215,12 @@ class CRU_BASE_API SubProcess : public Object { public: static SubProcess Create( - String program, std::vector<String> arguments = {}, - std::unordered_map<String, String> environments = {}); + std::string program, std::vector<std::string> arguments = {}, + std::unordered_map<std::string, std::string> environments = {}); static SubProcessExitResult Call( - String program, std::vector<String> arguments = {}, - std::unordered_map<String, String> environments = {}); + std::string program, std::vector<std::string> arguments = {}, + std::unordered_map<std::string, std::string> 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 <cstddef> 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,42 +2,12 @@ #include "Exception.h" #include "Resource.h" -#include "cru/base/String.h" - #include <memory> #include <type_traits> namespace cru::platform { template <typename TTarget> TTarget* CheckPlatform(IPlatformResource* resource, - const String& target_platform) { - if (resource == nullptr) return nullptr; - const auto result = dynamic_cast<TTarget*>(resource); - if (result == nullptr) { - throw PlatformNotMatchException( - resource->GetPlatformId(), target_platform, - u"Try to convert resource to target platform failed."); - } - return result; -} - -template <typename TTarget, typename TSource> -std::shared_ptr<TTarget> CheckPlatform(const std::shared_ptr<TSource>& resource, - const String& target_platform) { - if (resource == nullptr) return nullptr; - static_assert(std::is_base_of_v<IPlatformResource, TSource>, - "TSource must be a subclass of INativeResource."); - const auto result = std::dynamic_pointer_cast<TTarget>(resource); - if (result == nullptr) { - throw PlatformNotMatchException( - resource->GetPlatformId(), target_platform, - u"Try to convert resource to target platform failed."); - } - return result; -} - -template <typename TTarget> -TTarget* CheckPlatform(IPlatformResource* resource, std::string target_platform) { if (resource == nullptr) return nullptr; const auto result = dynamic_cast<TTarget*>(resource); 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<std::string_view> additional_message = std::nullopt); - PlatformNotMatchException( - StringView resource_platform, StringView target_platform, - std::optional<StringView> 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<std::string_view> additional_message); - PlatformUnsupportedException(StringView platform, StringView operation, - std::optional<StringView> 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 <any> #include <filesystem> +#include <format> #include <typeindex> #include <typeinfo> @@ -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); |