aboutsummaryrefslogtreecommitdiff
path: root/include/cru
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru')
-rw-r--r--include/cru/base/Exception.h8
-rw-r--r--include/cru/base/io/Stream.h14
-rw-r--r--include/cru/platform/Color.h6
-rw-r--r--include/cru/platform/Exception.h31
-rw-r--r--include/cru/platform/GraphicsBase.h7
-rw-r--r--include/cru/platform/graphics/SvgGeometryBuilderMixin.h5
-rw-r--r--include/cru/ui/ThemeManager.h1
-rw-r--r--include/cru/ui/ThemeResourceDictionary.h1
-rw-r--r--include/cru/ui/render/MeasureRequirement.h24
9 files changed, 70 insertions, 27 deletions
diff --git a/include/cru/base/Exception.h b/include/cru/base/Exception.h
index a898043a..4fcd96ad 100644
--- a/include/cru/base/Exception.h
+++ b/include/cru/base/Exception.h
@@ -30,9 +30,15 @@ class CRU_BASE_API Exception : public std::exception {
const char* what() const noexcept override;
protected:
- void SetMessage(StringView message) { message_ = message.ToUtf8(); }
+ void SetMessage(std::string message) { message_ = std::move(message); }
+ 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:
diff --git a/include/cru/base/io/Stream.h b/include/cru/base/io/Stream.h
index 0965cf22..2f02a8c2 100644
--- a/include/cru/base/io/Stream.h
+++ b/include/cru/base/io/Stream.h
@@ -10,12 +10,16 @@
namespace cru::io {
class CRU_BASE_API StreamOperationNotSupportedException : public Exception {
public:
- explicit StreamOperationNotSupportedException(String operation);
-
- CRU_DEFAULT_DESTRUCTOR(StreamOperationNotSupportedException)
+ explicit StreamOperationNotSupportedException(StringView operation);
+ explicit StreamOperationNotSupportedException(std::string operation);
public:
- String GetOperation() const { return operation_; }
+ [[deprecated("Use GetOperationUtf8 instead.")]]
+ String GetOperation() const {
+ return String::FromUtf8(operation_);
+ }
+
+ std::string GetOperationUtf8() const { return operation_; }
public:
static void CheckSeek(bool seekable);
@@ -23,7 +27,7 @@ class CRU_BASE_API StreamOperationNotSupportedException : public Exception {
static void CheckWrite(bool writable);
private:
- String operation_;
+ std::string operation_;
};
class CRU_BASE_API StreamClosedException : public Exception {
diff --git a/include/cru/platform/Color.h b/include/cru/platform/Color.h
index d993bd43..54308bbd 100644
--- a/include/cru/platform/Color.h
+++ b/include/cru/platform/Color.h
@@ -2,10 +2,10 @@
#include "Base.h"
#include "cru/base/Base.h"
-#include "cru/base/Format.h"
#include "cru/base/String.h"
#include <cstdint>
+#include <format>
#include <optional>
#include <unordered_map>
@@ -258,8 +258,8 @@ extern const std::unordered_map<StringView, Color> predefined_name_color_map;
std::optional<Color> GetPredefinedColorByName(StringView name);
inline String ToString(const Color& color) {
- return cru::Format(u"rgba({}, {}, {}, {})", color.red, color.green,
- color.blue, color.alpha);
+ return String::FromUtf8(std::format("rgba({}, {}, {}, {})", color.red,
+ color.green, color.blue, color.alpha));
}
struct CRU_PLATFORM_API HslColor {
diff --git a/include/cru/platform/Exception.h b/include/cru/platform/Exception.h
index 4f9dc9ce..25017869 100644
--- a/include/cru/platform/Exception.h
+++ b/include/cru/platform/Exception.h
@@ -4,6 +4,7 @@
#include "cru/base/Exception.h"
#include <optional>
+#include <string_view>
namespace cru::platform {
// This exception is thrown when a resource is used on another platform.
@@ -12,17 +13,26 @@ namespace cru::platform {
class CRU_PLATFORM_API PlatformNotMatchException : public PlatformException {
public:
PlatformNotMatchException(
- String resource_platform, String target_platform,
+ std::string resource_platform, std::string target_platform,
+ std::optional<std::string> 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_; }
+
private:
- String resource_platform_;
- String target_platform_;
+ std::string resource_platform_;
+ std::string target_platform_;
};
// This exception is thrown when a resource has been disposed and not usable
@@ -38,16 +48,25 @@ class CRU_PLATFORM_API ReuseException : public Exception {
class CRU_PLATFORM_API PlatformUnsupportedException : public PlatformException {
public:
- PlatformUnsupportedException(String platform, String operation,
+ PlatformUnsupportedException(
+ 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_; }
+
private:
- String platform_;
- String operation_;
+ std::string platform_;
+ std::string operation_;
};
} // namespace cru::platform
diff --git a/include/cru/platform/GraphicsBase.h b/include/cru/platform/GraphicsBase.h
index 4837b08b..3d131e22 100644
--- a/include/cru/platform/GraphicsBase.h
+++ b/include/cru/platform/GraphicsBase.h
@@ -1,10 +1,10 @@
#pragma once
#include "Base.h"
-#include "cru/base/Format.h"
#include "cru/base/Range.h"
#include "cru/base/String.h"
+#include <format>
#include <limits>
namespace cru::platform {
@@ -44,7 +44,7 @@ constexpr bool operator!=(const Point& left, const Point& right) {
}
inline String ToString(const Point& point) {
- return Format(u"(x: {}, y: {})", point.x, point.y);
+ return String::FromUtf8(std::format("(x: {}, y: {})", point.x, point.y));
}
struct CRU_PLATFORM_API Size final {
@@ -85,7 +85,8 @@ constexpr bool operator!=(const Size& left, const Size& right) {
}
inline String ToString(const Size& size) {
- return Format(u"(width: {}, height: {})", size.width, size.height);
+ return String::FromUtf8(
+ std::format("(width: {}, height: {})", size.width, size.height));
}
struct Thickness final {
diff --git a/include/cru/platform/graphics/SvgGeometryBuilderMixin.h b/include/cru/platform/graphics/SvgGeometryBuilderMixin.h
index 1f7420e9..32b665a5 100644
--- a/include/cru/platform/graphics/SvgGeometryBuilderMixin.h
+++ b/include/cru/platform/graphics/SvgGeometryBuilderMixin.h
@@ -1,8 +1,8 @@
#pragma once
#include "Geometry.h"
-#include "cru/base/Format.h"
+#include <format>
#include <utility>
namespace cru::platform::graphics {
@@ -53,7 +53,8 @@ class CRU_PLATFORM_GRAPHICS_API SvgGeometryBuilderMixin
private:
template <typename... Args>
void Append(StringView format, Args&&... args) {
- current_ += Format(format, std::forward<Args>(args)...);
+ current_ += String::FromUtf8(
+ std::format(format.ToUtf8(), std::forward<Args>(args)...));
current_ += u' ';
}
diff --git a/include/cru/ui/ThemeManager.h b/include/cru/ui/ThemeManager.h
index d4e6a096..f3f01313 100644
--- a/include/cru/ui/ThemeManager.h
+++ b/include/cru/ui/ThemeManager.h
@@ -1,6 +1,7 @@
#pragma once
#include "Base.h"
#include "cru/base/Event.h"
+#include "cru/base/Format.h"
#include "cru/ui/ThemeResourceDictionary.h"
#include <vector>
diff --git a/include/cru/ui/ThemeResourceDictionary.h b/include/cru/ui/ThemeResourceDictionary.h
index 597fe707..c3fcfde2 100644
--- a/include/cru/ui/ThemeResourceDictionary.h
+++ b/include/cru/ui/ThemeResourceDictionary.h
@@ -2,6 +2,7 @@
#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"
diff --git a/include/cru/ui/render/MeasureRequirement.h b/include/cru/ui/render/MeasureRequirement.h
index 3f4e0a3d..544e0788 100644
--- a/include/cru/ui/render/MeasureRequirement.h
+++ b/include/cru/ui/render/MeasureRequirement.h
@@ -4,7 +4,9 @@
#include "cru/base/String.h"
#include <algorithm>
+#include <format>
#include <limits>
+#include <string>
namespace cru::ui::render {
constexpr Size Min(const Size& left, const Size& right) {
@@ -111,10 +113,13 @@ class MeasureLength final {
}
}
- String ToDebugString() const {
- return IsSpecified() ? ToString(GetLengthOrUndefined()) : u"UNSPECIFIED";
+ std::string ToDebugStringUtf8() const {
+ return IsSpecified() ? std::to_string(GetLengthOrUndefined())
+ : "UNSPECIFIED";
}
+ String ToDebugString() const { return String::FromUtf8(ToDebugStringUtf8()); }
+
private:
// -1 for not specify
float length_;
@@ -163,10 +168,13 @@ struct MeasureSize {
};
}
- String ToDebugString() const {
- return Format(u"({}, {})", width.ToDebugString(), height.ToDebugString());
+ std::string ToDebugStringUtf8() const {
+ return std::format("({}, {})", width.ToDebugStringUtf8(),
+ height.ToDebugStringUtf8());
}
+ String ToDebugString() const { return String::FromUtf8(ToDebugStringUtf8()); }
+
constexpr static MeasureSize NotSpecified() {
return MeasureSize{MeasureLength::NotSpecified(),
MeasureLength::NotSpecified()};
@@ -233,11 +241,13 @@ struct MeasureRequirement {
return result;
}
- String ToDebugString() const {
- return Format(u"{{min: {}, max: {}}}", min.ToDebugString(),
- max.ToDebugString());
+ std::string ToDebugStringUtf8() const {
+ return std::format("{{min: {}, max: {}}}", min.ToDebugStringUtf8(),
+ max.ToDebugStringUtf8());
}
+ String ToDebugString() const { return String::FromUtf8(ToDebugStringUtf8()); }
+
constexpr static MeasureRequirement Merge(const MeasureRequirement& left,
const MeasureRequirement& right) {
return MeasureRequirement{MeasureSize::Min(left.max, right.max),