aboutsummaryrefslogtreecommitdiff
path: root/include/cru/base
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-10-17 10:01:30 +0800
committerYuqian Yang <crupest@crupest.life>2025-10-17 10:01:30 +0800
commitfaf77949e19dc0d01f75bf8abb783eda70328048 (patch)
tree0448c642573157d79a984ab19b3396210e91acca /include/cru/base
parent9e4419826b3e23c63567591701a2834a837da98e (diff)
downloadcru-faf77949e19dc0d01f75bf8abb783eda70328048.tar.gz
cru-faf77949e19dc0d01f75bf8abb783eda70328048.tar.bz2
cru-faf77949e19dc0d01f75bf8abb783eda70328048.zip
Platform base no String.
Diffstat (limited to 'include/cru/base')
-rw-r--r--include/cru/base/StringUtil.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/include/cru/base/StringUtil.h b/include/cru/base/StringUtil.h
index d79c0c23..0ce3802f 100644
--- a/include/cru/base/StringUtil.h
+++ b/include/cru/base/StringUtil.h
@@ -3,8 +3,8 @@
#include "Bitmask.h"
#include <compare>
+#include <format>
#include <functional>
-#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>
@@ -30,6 +30,25 @@ struct SplitOptions {
std::vector<std::string> Split(std::string_view str, std::string_view sep,
SplitOption options = {});
+
+template <typename T>
+struct ImplementFormatterByToString {
+ template <class ParseContext>
+ constexpr ParseContext::iterator parse(ParseContext& ctx) const {
+ auto iter = ctx.begin();
+ if (*iter != '}') {
+ throw std::format_error(
+ "ImplementFormatterByToString does not accept format args.");
+ }
+ return iter;
+ }
+
+ template <class FmtContext>
+ FmtContext::iterator format(const T& object, FmtContext& ctx) const {
+ return std::ranges::copy(object.ToString(), ctx.out()).out;
+ }
+};
+
} // namespace string
using CodePoint = std::int32_t;