1
0

Compare commits

..

2 Commits

Author SHA1 Message Date
82c3ed5b32 fix: fix compile error in gcc.
- remove __attribute__(format) checker for UTF8 char type printf becuase it forcely require the type of format string is const char*, rather than const char8_t*, and I can not use any switches to remove this.
- delete useless macro and header in clap manual.
2025-09-28 22:38:09 +08:00
d6be8a11ac fix: use more clear format spec in format test.
- this is designed to avoid different behavior between msvc and gcc.
	- gcc output char in default.
	- msvc output it as integer in default.
2025-09-28 22:31:08 +08:00
3 changed files with 11 additions and 7 deletions

View File

@ -2,13 +2,11 @@
#include "../termcolor.hpp"
#include "../../patch/stream.hpp"
#include "../../patch/format.hpp"
#include "../../string/op.hpp"
#define CLAP ::yycc::carton::clap
#define TABULATE ::yycc::carton::tabulate
#define TERMCOLOR ::yycc::carton::termcolor
#define FORMAT ::yycc::patch::format
#define OP ::yycc::carton::op
using namespace ::yycc::patch::stream;

View File

@ -12,13 +12,19 @@ namespace yycc::string::op {
#pragma region Printf
// YYC MARK:
// Shitty __attribute__((format(gnu_printf, (A), (B)))) force the type of format string is const char*.
// My function signature will cause compile error which can not be removed by any switches.
// I guess Clang may have same issue.
// So I sadly disable format string check for printf in UTF8 char type.
/**
* @brief Perform an UTF8 string formatting operation.
* @param[in] format The format string.
* @param[in] ... Argument list of format string.
* @return The formatted result.
*/
std::u8string printf(YYCC_PRINTF_CHECK_FMTSTR const char8_t* format, ...) YYCC_PRINTF_CHECK_ATTR(1, 2);
std::u8string printf(/*YYCC_PRINTF_CHECK_FMTSTR*/ const char8_t* format, ...) /*YYCC_PRINTF_CHECK_ATTR(1, 2)*/;
/**
* @brief Perform an UTF8 string formatting operation.
* @param[in] format The format string.

View File

@ -11,25 +11,25 @@ namespace yycctest::patch::format {
static constexpr std::u8string_view PROBE_STRING_VIEW(PROBE);
TEST(PatchFormat, OrdinaryFormat) {
auto rv = FORMAT::format("{}{}{}{}{}{} world!",
auto rv = FORMAT::format("{:c}{}{}{}{}{} world!",
PROBE[0],
PROBE_STRING.data(),
PROBE_STRING.c_str(),
PROBE,
PROBE_STRING,
PROBE_STRING_VIEW);
EXPECT_EQ(rv, "104hellohellohellohellohello world!");
EXPECT_EQ(rv, "hhellohellohellohellohello world!");
}
TEST(PatchFormat, Utf8Format) {
auto rv = FORMAT::format(u8"{}{}{}{}{}{} world!",
auto rv = FORMAT::format(u8"{:c}{}{}{}{}{} world!",
PROBE[0],
PROBE_STRING.data(),
PROBE_STRING.c_str(),
PROBE,
PROBE_STRING,
PROBE_STRING_VIEW);
EXPECT_EQ(rv, u8"104hellohellohellohellohello world!");
EXPECT_EQ(rv, u8"hhellohellohellohellohello world!");
}
}