refactor: move YYCC_U8 from reinterpret.hpp to string.hpp
- move YYCC_U8 def. - create shared template in testbench.
This commit is contained in:
@ -40,6 +40,7 @@ namespace yycc::num::stringify {
|
|||||||
std::chars_format fmt = std::chars_format::general,
|
std::chars_format fmt = std::chars_format::general,
|
||||||
int precision = 6) {
|
int precision = 6) {
|
||||||
namespace reinterpret = NS_YYCC_STRING_REINTERPRET;
|
namespace reinterpret = NS_YYCC_STRING_REINTERPRET;
|
||||||
|
|
||||||
StringifyBuffer buffer;
|
StringifyBuffer buffer;
|
||||||
auto [ptr, ec] = std::to_chars(reinterpret::as_ordinary(buffer.data()),
|
auto [ptr, ec] = std::to_chars(reinterpret::as_ordinary(buffer.data()),
|
||||||
reinterpret::as_ordinary(buffer.data() + buffer.size()),
|
reinterpret::as_ordinary(buffer.data() + buffer.size()),
|
||||||
@ -67,6 +68,7 @@ namespace yycc::num::stringify {
|
|||||||
template<typename T, std::enable_if_t<std::is_integral_v<T> && !std::is_same_v<T, bool>, int> = 0>
|
template<typename T, std::enable_if_t<std::is_integral_v<T> && !std::is_same_v<T, bool>, int> = 0>
|
||||||
NS_YYCC_STRING::u8string stringify(T num, int base = 10) {
|
NS_YYCC_STRING::u8string stringify(T num, int base = 10) {
|
||||||
namespace reinterpret = NS_YYCC_STRING_REINTERPRET;
|
namespace reinterpret = NS_YYCC_STRING_REINTERPRET;
|
||||||
|
|
||||||
StringifyBuffer buffer;
|
StringifyBuffer buffer;
|
||||||
auto [ptr, ec] = std::to_chars(reinterpret::as_ordinary(buffer.data()),
|
auto [ptr, ec] = std::to_chars(reinterpret::as_ordinary(buffer.data()),
|
||||||
reinterpret::as_ordinary(buffer.data() + buffer.size()),
|
reinterpret::as_ordinary(buffer.data() + buffer.size()),
|
||||||
|
@ -39,4 +39,9 @@ namespace yycc::string {
|
|||||||
using u8string = std::basic_string<u8char>;
|
using u8string = std::basic_string<u8char>;
|
||||||
using u8string_view = std::basic_string_view<u8char>;
|
using u8string_view = std::basic_string_view<u8char>;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define _YYCC_U8(strl) u8 ## strl ///< The assistant macro for YYCC_U8.
|
||||||
|
#define YYCC_U8(strl) (reinterpret_cast<const ::yycc::string::u8char*>(_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
|
} // namespace yycc::string
|
||||||
|
@ -19,6 +19,8 @@ namespace yycc::string::op {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool vprintf(NS_YYCC_STRING::u8string& strl, const NS_YYCC_STRING::u8char* format, va_list argptr) {
|
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_list args1;
|
||||||
va_copy(args1, argptr);
|
va_copy(args1, argptr);
|
||||||
va_list args2;
|
va_list args2;
|
||||||
@ -29,7 +31,7 @@ namespace yycc::string::op {
|
|||||||
int count = std::vsnprintf(
|
int count = std::vsnprintf(
|
||||||
nullptr,
|
nullptr,
|
||||||
0,
|
0,
|
||||||
NS_YYCC_STRING_REINTERPRET::as_ordinary(format),
|
reinterpret::as_ordinary(format),
|
||||||
args1
|
args1
|
||||||
);
|
);
|
||||||
if (count < 0) {
|
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.
|
// however std::vsnprintf already have a trailing NULL, so we plus 1 for it.
|
||||||
strl.resize(count);
|
strl.resize(count);
|
||||||
int write_result = std::vsnprintf(
|
int write_result = std::vsnprintf(
|
||||||
NS_YYCC_STRING_REINTERPRET::as_ordinary(strl.data()),
|
reinterpret::as_ordinary(strl.data()),
|
||||||
strl.size() + 1,
|
strl.size() + 1,
|
||||||
NS_YYCC_STRING_REINTERPRET::as_ordinary(format),
|
reinterpret::as_ordinary(format),
|
||||||
args2
|
args2
|
||||||
);
|
);
|
||||||
va_end(args2);
|
va_end(args2);
|
||||||
|
@ -12,10 +12,6 @@
|
|||||||
*/
|
*/
|
||||||
namespace yycc::string::reinterpret {
|
namespace yycc::string::reinterpret {
|
||||||
|
|
||||||
#define _YYCC_U8(strl) u8 ## strl ///< The assistant macro for YYCC_U8.
|
|
||||||
#define YYCC_U8(strl) (reinterpret_cast<const ::yycc::string::u8char*>(_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).
|
* @brief Reinterpret ordinary C-string to UTF-8 string (const version).
|
||||||
* @param src Source ordinary string
|
* @param src Source ordinary string
|
||||||
|
@ -15,6 +15,14 @@ PRIVATE
|
|||||||
yycc/patch/contains.cpp
|
yycc/patch/contains.cpp
|
||||||
yycc/patch/starts_ends_with.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
|
# Setup headers
|
||||||
target_include_directories(YYCCTestbench
|
target_include_directories(YYCCTestbench
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
0
testbench/shared/parse_template.hpp
Normal file
0
testbench/shared/parse_template.hpp
Normal file
0
testbench/shared/stringify_template.hpp
Normal file
0
testbench/shared/stringify_template.hpp
Normal file
0
testbench/shared/utf_literal.hpp
Normal file
0
testbench/shared/utf_literal.hpp
Normal file
@ -1,7 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yycc.hpp>
|
#include <yycc.hpp>
|
||||||
#include <yycc/constraint/builder.hpp>
|
#include <yycc/constraint/builder.hpp>
|
||||||
#include <yycc/string/reinterpret.hpp>
|
|
||||||
|
|
||||||
#include <yycc/prelude/rust.hpp>
|
#include <yycc/prelude/rust.hpp>
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yycc.hpp>
|
#include <yycc.hpp>
|
||||||
#include <yycc/num/parse.hpp>
|
#include <yycc/num/parse.hpp>
|
||||||
#include <yycc/string/reinterpret.hpp>
|
|
||||||
|
|
||||||
#include <yycc/prelude/rust.hpp>
|
#include <yycc/prelude/rust.hpp>
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yycc.hpp>
|
#include <yycc.hpp>
|
||||||
#include <yycc/num/stringify.hpp>
|
#include <yycc/num/stringify.hpp>
|
||||||
#include <yycc/string/reinterpret.hpp>
|
|
||||||
|
|
||||||
#include <yycc/prelude/rust.hpp>
|
#include <yycc/prelude/rust.hpp>
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yycc.hpp>
|
#include <yycc.hpp>
|
||||||
#include <yycc/string/op.hpp>
|
#include <yycc/string/op.hpp>
|
||||||
#include <yycc/string/reinterpret.hpp>
|
|
||||||
|
|
||||||
#include <yycc/prelude/core.hpp>
|
#include <yycc/prelude/core.hpp>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user