diff --git a/src/yycc/num/stringify.hpp b/src/yycc/num/stringify.hpp index 1a048be..3ae2492 100644 --- a/src/yycc/num/stringify.hpp +++ b/src/yycc/num/stringify.hpp @@ -40,6 +40,7 @@ namespace yycc::num::stringify { std::chars_format fmt = std::chars_format::general, int precision = 6) { namespace reinterpret = NS_YYCC_STRING_REINTERPRET; + StringifyBuffer buffer; auto [ptr, ec] = std::to_chars(reinterpret::as_ordinary(buffer.data()), reinterpret::as_ordinary(buffer.data() + buffer.size()), @@ -67,6 +68,7 @@ namespace yycc::num::stringify { template && !std::is_same_v, int> = 0> NS_YYCC_STRING::u8string stringify(T num, int base = 10) { namespace reinterpret = NS_YYCC_STRING_REINTERPRET; + StringifyBuffer buffer; auto [ptr, ec] = std::to_chars(reinterpret::as_ordinary(buffer.data()), reinterpret::as_ordinary(buffer.data() + buffer.size()), diff --git a/src/yycc/string.hpp b/src/yycc/string.hpp index 64f0d13..f1f2f20 100644 --- a/src/yycc/string.hpp +++ b/src/yycc/string.hpp @@ -39,4 +39,9 @@ namespace yycc::string { using u8string = std::basic_string; using u8string_view = std::basic_string_view; #endif + +#define _YYCC_U8(strl) u8 ## strl ///< The assistant macro for YYCC_U8. +#define YYCC_U8(strl) (reinterpret_cast(_YYCC_U8(strl))) ///< The macro for creating UTF8 string literal. See \ref library_encoding. +#define YYCC_U8_CHAR(chr) (static_cast<::yycc::string::u8char>(chr)) ///< The macro for casting ordinary char type into YYCC UTF8 char type. + } // namespace yycc::string diff --git a/src/yycc/string/op.cpp b/src/yycc/string/op.cpp index c277110..0916321 100644 --- a/src/yycc/string/op.cpp +++ b/src/yycc/string/op.cpp @@ -19,6 +19,8 @@ namespace yycc::string::op { } bool vprintf(NS_YYCC_STRING::u8string& strl, const NS_YYCC_STRING::u8char* format, va_list argptr) { + namespace reinterpret = NS_YYCC_STRING_REINTERPRET; + va_list args1; va_copy(args1, argptr); va_list args2; @@ -29,7 +31,7 @@ namespace yycc::string::op { int count = std::vsnprintf( nullptr, 0, - NS_YYCC_STRING_REINTERPRET::as_ordinary(format), + reinterpret::as_ordinary(format), args1 ); if (count < 0) { @@ -44,9 +46,9 @@ namespace yycc::string::op { // however std::vsnprintf already have a trailing NULL, so we plus 1 for it. strl.resize(count); int write_result = std::vsnprintf( - NS_YYCC_STRING_REINTERPRET::as_ordinary(strl.data()), + reinterpret::as_ordinary(strl.data()), strl.size() + 1, - NS_YYCC_STRING_REINTERPRET::as_ordinary(format), + reinterpret::as_ordinary(format), args2 ); va_end(args2); diff --git a/src/yycc/string/reinterpret.hpp b/src/yycc/string/reinterpret.hpp index 9bab48f..e2d454b 100644 --- a/src/yycc/string/reinterpret.hpp +++ b/src/yycc/string/reinterpret.hpp @@ -12,10 +12,6 @@ */ namespace yycc::string::reinterpret { -#define _YYCC_U8(strl) u8 ## strl ///< The assistant macro for YYCC_U8. -#define YYCC_U8(strl) (reinterpret_cast(_YYCC_U8(strl))) ///< The macro for creating UTF8 string literal. See \ref library_encoding. -#define YYCC_U8_CHAR(chr) (static_cast<::yycc::string::u8char>(chr)) ///< The macro for casting ordinary char type into YYCC UTF8 char type. - /** * @brief Reinterpret ordinary C-string to UTF-8 string (const version). * @param src Source ordinary string diff --git a/testbench/CMakeLists.txt b/testbench/CMakeLists.txt index 2021aa6..08c99b5 100644 --- a/testbench/CMakeLists.txt +++ b/testbench/CMakeLists.txt @@ -15,6 +15,14 @@ PRIVATE yycc/patch/contains.cpp yycc/patch/starts_ends_with.cpp ) +target_sources(YYCCTestbench +PRIVATE +FILE_SET HEADERS +FILES + shared/parse_template.hpp + shared/stringify_template.hpp + shared/utf_literal.hpp +) # Setup headers target_include_directories(YYCCTestbench PUBLIC diff --git a/testbench/shared/parse_template.hpp b/testbench/shared/parse_template.hpp new file mode 100644 index 0000000..e69de29 diff --git a/testbench/shared/stringify_template.hpp b/testbench/shared/stringify_template.hpp new file mode 100644 index 0000000..e69de29 diff --git a/testbench/shared/utf_literal.hpp b/testbench/shared/utf_literal.hpp new file mode 100644 index 0000000..e69de29 diff --git a/testbench/yycc/constraint/builder.cpp b/testbench/yycc/constraint/builder.cpp index 059e36c..f043533 100644 --- a/testbench/yycc/constraint/builder.cpp +++ b/testbench/yycc/constraint/builder.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include diff --git a/testbench/yycc/num/parse.cpp b/testbench/yycc/num/parse.cpp index 18631f6..8bbda10 100644 --- a/testbench/yycc/num/parse.cpp +++ b/testbench/yycc/num/parse.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include diff --git a/testbench/yycc/num/stringify.cpp b/testbench/yycc/num/stringify.cpp index 52850f6..27cd58c 100644 --- a/testbench/yycc/num/stringify.cpp +++ b/testbench/yycc/num/stringify.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include diff --git a/testbench/yycc/string/op.cpp b/testbench/yycc/string/op.cpp index 47453fa..f74638d 100644 --- a/testbench/yycc/string/op.cpp +++ b/testbench/yycc/string/op.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include