1
0

fix: redirect all std::format to my personal format

This commit is contained in:
2025-09-28 21:44:44 +08:00
parent 8d7eff2a15
commit d6b1d7fd46
3 changed files with 6 additions and 10 deletions

View File

@ -19,7 +19,6 @@
namespace yycc::patch::format { namespace yycc::patch::format {
// TODO: order all use of std::format redirect to this function.
// TODO: all use of OP::printf should also switch to this function if possible. // TODO: all use of OP::printf should also switch to this function if possible.
template<class... Args> template<class... Args>

View File

@ -18,7 +18,7 @@ namespace yycc::rust::panic {
// It seems that STL providers are not ready for this feature. So I decide remove it entirely. // It seems that STL providers are not ready for this feature. So I decide remove it entirely.
// Once every STL probiders have ready for this, I will add it back. // Once every STL probiders have ready for this, I will add it back.
void panic(const char* file, int line, const std::string_view& msg) { void panic(const char* file, int line, const std::u8string_view& msg) {
// Output message in stderr. // Output message in stderr.
auto& dst = std::cerr; auto& dst = std::cerr;

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include "../patch/format.hpp"
#include <string_view> #include <string_view>
#include <format> #include <format>
@ -22,19 +23,15 @@
*/ */
namespace yycc::rust::panic { namespace yycc::rust::panic {
/**
* @brief Immediately crashes the entire program like Rust's \c panic! macro.
* @details The macro parameter is the additional message to display.
*/
#define RS_PANIC(msg) ::yycc::rust::panic::panic(__FILE__, __LINE__, (msg))
/** /**
* @brief Immediately crashes the entire program like Rust's \c panic! macro. * @brief Immediately crashes the entire program like Rust's \c panic! macro.
* @details * @details
* The macro parameters are the message to format and its arguments, following \c std::format syntax. * The macro parameters are the message to format and its arguments, following \c std::format syntax.
* This macro essentially calls \c std::format internally. * This macro essentially calls \c std::format internally.
* However, this format function is specially modified that it can accept UTF8 format string and UTF8 string argument.
* More preciously, it is "format" in \c yycc::patch::format namespace.
*/ */
#define RS_PANICF(msg, ...) RS_PANIC(std::format(msg __VA_OPT__(,) __VA_ARGS__)) #define RS_PANIC(msg, ...) ::yycc::rust::panic::panic(__FILE__, __LINE__, ::yycc::patch::format::format(msg __VA_OPT__(, ) __VA_ARGS__))
/** /**
* @brief Immediately crashes the entire program like Rust's \c panic! macro. * @brief Immediately crashes the entire program like Rust's \c panic! macro.
@ -45,6 +42,6 @@ namespace yycc::rust::panic {
* @param[in] line Line number in source file where panic occurred. Usually filled by macros. * @param[in] line Line number in source file where panic occurred. Usually filled by macros.
* @param[in] msg Message to display during panic. * @param[in] msg Message to display during panic.
*/ */
[[noreturn]] void panic(const char* file, int line, const std::string_view& msg); [[noreturn]] void panic(const char* file, int line, const std::u8string_view& msg);
} // namespace yycc::rust::panic } // namespace yycc::rust::panic