aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp6
-rw-r--r--src/ThemeBuilder/components/properties/PointPropertyEditor.cpp5
-rw-r--r--src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp1
-rw-r--r--src/ThemeBuilder/components/stylers/StylerEditor.cpp1
-rw-r--r--src/base/Exception.cpp15
-rw-r--r--src/base/io/Stream.cpp13
-rw-r--r--src/base/platform/unix/PosixSpawnSubProcess.cpp54
-rw-r--r--src/base/platform/unix/UnixFileStream.cpp7
-rw-r--r--src/parse/Grammar.cpp7
-rw-r--r--src/platform/Exception.cpp61
-rw-r--r--src/platform/graphics/SvgGeometryBuilderMixin.cpp2
-rw-r--r--src/platform/gui/UiApplication.cpp2
-rw-r--r--src/ui/components/Input.cpp6
-rw-r--r--src/ui/style/StyleRuleSet.cpp1
23 files changed, 184 insertions, 94 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),
diff --git a/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp
index ad338e78..e359199f 100644
--- a/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp
+++ b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp
@@ -1,8 +1,9 @@
#include "MeasureLengthPropertyEditor.h"
-#include "cru/base/Format.h"
#include "cru/ui/mapper/MapperRegistry.h"
#include "cru/ui/render/MeasureRequirement.h"
+#include <string>
+
namespace cru::theme_builder::components::properties {
MeasureLengthPropertyEditor::MeasureLengthPropertyEditor() {
container_.AddChild(&label_);
@@ -32,6 +33,7 @@ void MeasureLengthPropertyEditor::SetValue(
if (!trigger_change) SuppressNextChangeEvent();
text_.SetText(measure_length_.IsNotSpecified()
? u"unspecified"
- : ToString(measure_length_.GetLengthOrUndefined()));
+ : String::FromUtf8(std::to_string(
+ measure_length_.GetLengthOrUndefined())));
}
} // namespace cru::theme_builder::components::properties
diff --git a/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp b/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp
index d8487209..f2d10cf7 100644
--- a/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp
+++ b/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp
@@ -1,8 +1,9 @@
#include "PointPropertyEditor.h"
-#include "cru/base/Format.h"
#include "cru/ui/mapper/MapperRegistry.h"
#include "cru/ui/mapper/PointMapper.h"
+#include <format>
+
namespace cru::theme_builder::components::properties {
PointPropertyEditor::PointPropertyEditor() {
container_.AddChild(&label_);
@@ -33,6 +34,6 @@ void PointPropertyEditor::SetValue(const ui::Point& point,
}
String PointPropertyEditor::ConvertPointToString(const ui::Point& point) {
- return Format(u"{} {}", point.x, point.y);
+ return String::FromUtf8(std::format("{} {}", point.x, point.y));
}
} // namespace cru::theme_builder::components::properties
diff --git a/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp
index 3e022bb1..955a44f7 100644
--- a/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp
+++ b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp
@@ -1,4 +1,5 @@
#include "ThicknessPropertyEditor.h"
+#include "cru/base/Format.h"
#include "cru/ui/mapper/MapperRegistry.h"
#include "cru/ui/mapper/ThicknessMapper.h"
diff --git a/src/ThemeBuilder/components/stylers/StylerEditor.cpp b/src/ThemeBuilder/components/stylers/StylerEditor.cpp
index 0348adbd..b3147a15 100644
--- a/src/ThemeBuilder/components/stylers/StylerEditor.cpp
+++ b/src/ThemeBuilder/components/stylers/StylerEditor.cpp
@@ -8,6 +8,7 @@
#include "MarginStylerEditor.h"
#include "PaddingStylerEditor.h"
#include "PreferredSizeStylerEditor.h"
+#include "cru/base/Exception.h"
#include "cru/ui/controls/FlexLayout.h"
#include "cru/ui/render/FlexLayoutRenderObject.h"
#include "cru/ui/style/Styler.h"
diff --git a/src/base/Exception.cpp b/src/base/Exception.cpp
index 2bf66fc6..571c115f 100644
--- a/src/base/Exception.cpp
+++ b/src/base/Exception.cpp
@@ -17,9 +17,20 @@ Exception::~Exception() {}
const char* Exception::what() const noexcept { return message_.c_str(); }
-void Exception::AppendMessage(StringView additional_message) {
+void Exception::AppendMessage(std::string_view additional_message) {
message_ += " ";
- message_ += additional_message.ToUtf8();
+ message_ += additional_message;
+}
+
+void Exception::AppendMessage(
+ std::optional<std::string_view> additional_message) {
+ if (additional_message) AppendMessage(*additional_message);
+}
+
+void Exception::SetMessage(StringView message) { SetMessage(message.ToUtf8()); }
+
+void Exception::AppendMessage(StringView additional_message) {
+ AppendMessage(std::string_view(additional_message.ToUtf8()));
}
void Exception::AppendMessage(std::optional<StringView> additional_message) {
diff --git a/src/base/io/Stream.cpp b/src/base/io/Stream.cpp
index 1944ea7e..9b7ef856 100644
--- a/src/base/io/Stream.cpp
+++ b/src/base/io/Stream.cpp
@@ -1,15 +1,18 @@
#include "cru/base/io/Stream.h"
#include "cru/base/Exception.h"
-#include "cru/base/Format.h"
+#include <format>
#include <utility>
namespace cru::io {
StreamOperationNotSupportedException::StreamOperationNotSupportedException(
- String operation)
- : operation_(std::move(operation)) {
- SetMessage(Format(u"Stream operation {} not supported.", operation_));
-}
+ StringView operation)
+ : StreamOperationNotSupportedException(operation.ToUtf8()) {}
+
+StreamOperationNotSupportedException::StreamOperationNotSupportedException(
+ std::string operation)
+ : Exception(std::format("Stream operation {} not supported.", operation)),
+ operation_(std::move(operation)) {}
void StreamOperationNotSupportedException::CheckSeek(bool seekable) {
if (!seekable) throw StreamOperationNotSupportedException(u"seek");
diff --git a/src/base/platform/unix/PosixSpawnSubProcess.cpp b/src/base/platform/unix/PosixSpawnSubProcess.cpp
index 4471c39c..f7d2e855 100644
--- a/src/base/platform/unix/PosixSpawnSubProcess.cpp
+++ b/src/base/platform/unix/PosixSpawnSubProcess.cpp
@@ -1,6 +1,5 @@
#include "cru/base/platform/unix/PosixSpawnSubProcess.h"
#include "cru/base/Exception.h"
-#include "cru/base/Format.h"
#include "cru/base/Guard.h"
#include "cru/base/String.h"
#include "cru/base/SubProcess.h"
@@ -10,7 +9,9 @@
#include <spawn.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <format>
#include <memory>
+#include <string_view>
#include <unordered_map>
namespace cru::platform::unix {
@@ -35,7 +36,7 @@ char** CreateCstrArray(const std::vector<String>& argv) {
char** CreateCstrArray(const std::unordered_map<String, String>& envp) {
std::vector<String> str_array;
for (auto& [key, value] : envp) {
- str_array.push_back(cru::Format(u"{}={}", key, value));
+ str_array.push_back(key + u"=" + value);
}
return CreateCstrArray(str_array);
}
@@ -54,7 +55,7 @@ void DestroyCstrArray(char** argv) {
void PosixSpawnSubProcessImpl::PlatformCreateProcess(
const SubProcessStartInfo& start_info) {
- auto check_error = [](int error, String message) {
+ auto check_error = [](int error, std::string message) {
if (error == 0) return;
std::unique_ptr<ErrnoException> inner(new ErrnoException(error));
throw SubProcessFailedToStartException(std::move(message),
@@ -63,49 +64,52 @@ void PosixSpawnSubProcessImpl::PlatformCreateProcess(
posix_spawn_file_actions_t file_actions;
check_error(posix_spawn_file_actions_init(&file_actions),
- u"Failed to call posix_spawn_file_actions_init.");
+ "Failed to call posix_spawn_file_actions_init.");
Guard file_actions_guard(
[&file_actions] { posix_spawn_file_actions_destroy(&file_actions); });
auto add_dup2 = [&check_error, &file_actions](int from, int to,
- StringView name) {
+ std::string_view name) {
check_error(
posix_spawn_file_actions_adddup2(&file_actions, from, to),
- Format(u"Failed to call posix_spawn_file_actions_adddup2 on {}.",
- name));
+ std::format("Failed to call posix_spawn_file_actions_adddup2 on {}.",
+ name));
};
auto add_close = [&check_error, &file_actions](
- UniDirectionalUnixPipeResult& pipe, StringView name) {
- check_error(posix_spawn_file_actions_addclose(&file_actions, pipe.read),
- Format(u"Failed to call posix_spawn_file_actions_addclose on "
- u"read end of pipe {}.",
- name));
- check_error(posix_spawn_file_actions_addclose(&file_actions, pipe.write),
- Format(u"Failed to call posix_spawn_file_actions_addclose on "
- u"write end of pipe {}.",
- name));
+ UniDirectionalUnixPipeResult& pipe,
+ std::string_view name) {
+ check_error(
+ posix_spawn_file_actions_addclose(&file_actions, pipe.read),
+ std::format("Failed to call posix_spawn_file_actions_addclose on "
+ "read end of pipe {}.",
+ name));
+ check_error(
+ posix_spawn_file_actions_addclose(&file_actions, pipe.write),
+ std::format("Failed to call posix_spawn_file_actions_addclose on "
+ "write end of pipe {}.",
+ name));
};
auto my_stdin = OpenUniDirectionalPipe();
auto my_stdout = OpenUniDirectionalPipe();
auto my_stderr = OpenUniDirectionalPipe();
- add_dup2(my_stdin.read, STDIN_FILENO, u"stdin");
- add_dup2(my_stdout.write, STDOUT_FILENO, u"stdout");
- add_dup2(my_stderr.write, STDERR_FILENO, u"stderr");
- add_close(my_stdin, u"stdin");
- add_close(my_stdout, u"stdout");
- add_close(my_stderr, u"stderr");
+ add_dup2(my_stdin.read, STDIN_FILENO, "stdin");
+ add_dup2(my_stdout.write, STDOUT_FILENO, "stdout");
+ add_dup2(my_stderr.write, STDERR_FILENO, "stderr");
+ add_close(my_stdin, "stdin");
+ add_close(my_stdout, "stdout");
+ add_close(my_stderr, "stderr");
posix_spawnattr_t attr;
check_error(posix_spawnattr_init(&attr),
- u"Failed to call posix_spawnattr_init.");
+ "Failed to call posix_spawnattr_init.");
Guard attr_guard([&attr] { posix_spawnattr_destroy(&attr); });
#ifdef __APPLE__
check_error(posix_spawnattr_setflags(&attr, POSIX_SPAWN_CLOEXEC_DEFAULT),
- u"Failed to set flag POSIX_SPAWN_CLOEXEC_DEFAULT (osx).");
+ "Failed to set flag POSIX_SPAWN_CLOEXEC_DEFAULT (osx).");
#endif
auto exe = start_info.program.ToUtf8();
@@ -121,7 +125,7 @@ void PosixSpawnSubProcessImpl::PlatformCreateProcess(
check_error(
posix_spawnp(&pid_, exe.c_str(), &file_actions, &attr, argv, envp),
- u"Failed to call posix_spawnp.");
+ "Failed to call posix_spawnp.");
stdin_stream_ = std::make_unique<UnixFileStream>(std::move(my_stdin.write),
false, false, true);
diff --git a/src/base/platform/unix/UnixFileStream.cpp b/src/base/platform/unix/UnixFileStream.cpp
index e1a6080b..0772c279 100644
--- a/src/base/platform/unix/UnixFileStream.cpp
+++ b/src/base/platform/unix/UnixFileStream.cpp
@@ -1,11 +1,11 @@
#include "cru/base/platform/unix/UnixFileStream.h"
#include "cru/base/Exception.h"
-#include "cru/base/Format.h"
#include "cru/base/io/Stream.h"
#include <fcntl.h>
#include <sys/fcntl.h>
#include <unistd.h>
+#include <format>
namespace cru::platform::unix {
using namespace cru::io;
@@ -41,9 +41,8 @@ int MapSeekOrigin(Stream::SeekOrigin origin) {
UnixFileStream::UnixFileStream(const char *path, int oflag, mode_t mode) {
file_descriptor_ = UnixFileDescriptor(::open(path, oflag, mode));
if (file_descriptor_ == -1) {
- throw ErrnoException(
- Format(u"Failed to open file {} with oflag {}, mode {}.",
- String::FromUtf8(path), oflag, mode));
+ throw ErrnoException(std::format(
+ "Failed to open file {} with oflag {}, mode {}.", path, oflag, mode));
}
SetSupportedOperations(
diff --git a/src/parse/Grammar.cpp b/src/parse/Grammar.cpp
index 12617de3..615901e0 100644
--- a/src/parse/Grammar.cpp
+++ b/src/parse/Grammar.cpp
@@ -1,9 +1,9 @@
#include "cru/parse/Grammar.h"
#include "cru/base/String.h"
#include "cru/parse/Symbol.h"
-#include "cru/base/Format.h"
#include <algorithm>
+#include <format>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
@@ -154,8 +154,9 @@ void Grammar::EliminateLeftRecursions() {
new_right.insert(new_right.cbegin(), jp->GetRight().cbegin(),
jp->GetRight().cend());
CreateProduction(
- Format(u"Merge of {} and {} (Eliminate Left Recursion)",
- production->GetName(), jp->GetName()),
+ String::FromUtf8(std::format(
+ "Merge of {} and {} (Eliminate Left Recursion)",
+ production->GetName().ToUtf8(), jp->GetName().ToUtf8())),
ni, std::move(new_right));
}
}
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 <format>
#include <optional>
+#include <string_view>
namespace cru::platform {
PlatformNotMatchException::PlatformNotMatchException(
- String resource_platform, String target_platform,
- std::optional<StringView> additional_message)
- : resource_platform_(std::move(resource_platform)),
+ std::string resource_platform, std::string target_platform,
+ std::optional<std::string> 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<StringView> 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<std::string_view> 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<StringView> 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;
diff --git a/src/ui/components/Input.cpp b/src/ui/components/Input.cpp
index b308ed51..6a53b938 100644
--- a/src/ui/components/Input.cpp
+++ b/src/ui/components/Input.cpp
@@ -1,9 +1,11 @@
#include "cru/ui/components/Input.h"
-#include <cmath>
-#include <optional>
+#include "cru/base/Format.h"
#include "cru/base/StringToNumberConverter.h"
#include "cru/ui/controls/Control.h"
+#include <cmath>
+#include <optional>
+
namespace cru::ui::components {
Input::Input() : last_validate_result_{true, u"Good value"} {
text_box_.TextChangeEvent()->AddSpyOnlyHandler([this] {
diff --git a/src/ui/style/StyleRuleSet.cpp b/src/ui/style/StyleRuleSet.cpp
index ab3a2d01..5468949a 100644
--- a/src/ui/style/StyleRuleSet.cpp
+++ b/src/ui/style/StyleRuleSet.cpp
@@ -1,5 +1,6 @@
#include "cru/ui/style/StyleRuleSet.h"
#include "cru/base/Event.h"
+#include "cru/base/Exception.h"
#include "cru/ui/controls/Control.h"
#include "cru/ui/model/IListChangeNotify.h"