diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ec954ad..2a943e9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,14 +44,14 @@ FILES yycc/string.hpp yycc/string/reinterpret.hpp yycc/string/op.hpp - yycc/string/parse.hpp - yycc/string/stringify.hpp + yycc/num/parse.hpp + yycc/num/stringify.hpp yycc/rust/primitive.hpp yycc/rust/panic.hpp yycc/rust/option.hpp yycc/rust/result.hpp - yycc/rust/parse.hpp - yycc/rust/stringify.hpp + yycc/rust/num/parse.hpp + yycc/rust/num/stringify.hpp yycc/windows/unsafe_suppressor.hpp yycc/windows/import_guard_head.hpp yycc/windows/import_guard_tail.hpp diff --git a/src/yycc/encoding/iconv.cpp b/src/yycc/encoding/iconv.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/yycc/encoding/iconv.hpp b/src/yycc/encoding/iconv.hpp new file mode 100644 index 0000000..e69de29 diff --git a/src/yycc/encoding/united_codec.cpp b/src/yycc/encoding/united_codec.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/yycc/encoding/united_codec.hpp b/src/yycc/encoding/united_codec.hpp new file mode 100644 index 0000000..e69de29 diff --git a/src/yycc/encoding/utf.hpp b/src/yycc/encoding/utf.hpp new file mode 100644 index 0000000..e69de29 diff --git a/src/yycc/encoding/windows.cpp b/src/yycc/encoding/windows.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/yycc/encoding/windows.hpp b/src/yycc/encoding/windows.hpp new file mode 100644 index 0000000..e69de29 diff --git a/src/yycc/string/parse.hpp b/src/yycc/num/parse.hpp similarity index 99% rename from src/yycc/string/parse.hpp rename to src/yycc/num/parse.hpp index a55b4ec..5c0fb91 100644 --- a/src/yycc/string/parse.hpp +++ b/src/yycc/num/parse.hpp @@ -1,7 +1,7 @@ #pragma once #include "../string.hpp" -#include "op.hpp" -#include "reinterpret.hpp" +#include "../string/op.hpp" +#include "../string/reinterpret.hpp" #include #include #include @@ -18,7 +18,7 @@ * and boolean values. It uses \c std::from_chars internally for efficient parsing. * @remarks See https://zh.cppreference.com/w/cpp/utility/from_chars for underlying called functions. */ -namespace yycc::string::parse { +namespace yycc::num::parse { /// @private /// @brief The error kind when parsing string into number. diff --git a/src/yycc/string/stringify.hpp b/src/yycc/num/stringify.hpp similarity index 98% rename from src/yycc/string/stringify.hpp rename to src/yycc/num/stringify.hpp index aebcff8..1a048be 100644 --- a/src/yycc/string/stringify.hpp +++ b/src/yycc/num/stringify.hpp @@ -1,6 +1,6 @@ #pragma once #include "../string.hpp" -#include "reinterpret.hpp" +#include "../string/reinterpret.hpp" #include #include #include @@ -18,7 +18,7 @@ * See https://en.cppreference.com/w/cpp/utility/to_chars for underlying called functions. * Default float precision = 6 is gotten from: https://en.cppreference.com/w/c/io/fprintf */ -namespace yycc::string::stringify { +namespace yycc::num::stringify { /// @private /// @brief Size of the internal buffer used for string conversion. diff --git a/src/yycc/rust/parse.hpp b/src/yycc/rust/num/parse.hpp similarity index 87% rename from src/yycc/rust/parse.hpp rename to src/yycc/rust/num/parse.hpp index 87e6215..6f2b65d 100644 --- a/src/yycc/rust/parse.hpp +++ b/src/yycc/rust/num/parse.hpp @@ -1,11 +1,11 @@ #pragma once -#include "../macro/feature_probe.hpp" -#include "../string/parse.hpp" -#include "panic.hpp" -#include "result.hpp" +#include "../../macro/feature_probe.hpp" +#include "../../num/parse.hpp" +#include "../panic.hpp" +#include "../result.hpp" #define NS_YYCC_STRING ::yycc::string -#define NS_YYCC_STRING_PARSE ::yycc::string::parse +#define NS_YYCC_NUM_PARSE ::yycc::num::parse #define NS_YYCC_RUST_RESULT ::yycc::rust::result /** @@ -15,12 +15,12 @@ * This namespace contains template functions for parsing strings into different types * (floating-point, integral, boolean) with Rust-like Result error handling. */ -namespace yycc::rust::parse { +namespace yycc::rust::num::parse { #if defined(YYCC_CPPFEAT_EXPECTED) /// @brief The error type of parsing. - using Error = NS_YYCC_STRING_PARSE::ParseError; + using Error = NS_YYCC_NUM_PARSE::ParseError; /// @brief The result type of parsing. /// @tparam T The expected value type in result. @@ -37,7 +37,7 @@ namespace yycc::rust::parse { template, int> = 0> Result parse(const NS_YYCC_STRING::u8string_view& strl, std::chars_format fmt = std::chars_format::general) { - auto rv = NS_YYCC_STRING_PARSE::priv_parse(strl, fmt); + auto rv = NS_YYCC_NUM_PARSE::priv_parse(strl, fmt); if (const auto* ptr = std::get_if(&rv)) { return NS_YYCC_RUST_RESULT::Ok>(*ptr); @@ -58,7 +58,7 @@ namespace yycc::rust::parse { */ template && !std::is_same_v, int> = 0> Result parse(const NS_YYCC_STRING::u8string_view& strl, int base = 10) { - auto rv = NS_YYCC_STRING_PARSE::priv_parse(strl, base); + auto rv = NS_YYCC_NUM_PARSE::priv_parse(strl, base); if (const auto* ptr = std::get_if(&rv)) { return NS_YYCC_RUST_RESULT::Ok>(*ptr); @@ -78,7 +78,7 @@ namespace yycc::rust::parse { */ template, int> = 0> Result parse(const NS_YYCC_STRING::u8string_view& strl) { - auto rv = NS_YYCC_STRING_PARSE::priv_parse(strl); + auto rv = NS_YYCC_NUM_PARSE::priv_parse(strl); if (const auto* ptr = std::get_if(&rv)) { return NS_YYCC_RUST_RESULT::Ok>(*ptr); @@ -95,5 +95,5 @@ namespace yycc::rust::parse { } #undef NS_YYCC_RUST_RESULT -#undef NS_YYCC_STRING_PARSE +#undef NS_YYCC_NUM_PARSE #undef NS_YYCC_STRING diff --git a/src/yycc/rust/stringify.hpp b/src/yycc/rust/num/stringify.hpp similarity index 62% rename from src/yycc/rust/stringify.hpp rename to src/yycc/rust/num/stringify.hpp index d360360..db7b199 100644 --- a/src/yycc/rust/stringify.hpp +++ b/src/yycc/rust/num/stringify.hpp @@ -1,10 +1,10 @@ #pragma once -#include "../string/stringify.hpp" +#include "../../num/stringify.hpp" -namespace yycc::rust::stringify { +namespace yycc::rust::num::stringify { // There is no modification for legacy "stringify" functions like "parse". // So we simply expose all functions into this namespace. - using namespace ::yycc::string::stringify; + using namespace ::yycc::num::stringify; } // namespace yycc::rust::stringify diff --git a/testbench/CMakeLists.txt b/testbench/CMakeLists.txt index 8e5d410..6692174 100644 --- a/testbench/CMakeLists.txt +++ b/testbench/CMakeLists.txt @@ -8,10 +8,10 @@ PRIVATE yycc/constraint/builder.cpp yycc/string/op.cpp yycc/string/reinterpret.cpp - yycc/string/parse.cpp - yycc/string/stringify.cpp - yycc/rust/parse.cpp - yycc/rust/stringify.cpp + yycc/num/parse.cpp + yycc/num/stringify.cpp + yycc/rust/num/parse.cpp + yycc/rust/num/stringify.cpp ) # Setup headers target_include_directories(YYCCTestbench diff --git a/testbench/yycc/string/parse.cpp b/testbench/yycc/num/parse.cpp similarity index 88% rename from testbench/yycc/string/parse.cpp rename to testbench/yycc/num/parse.cpp index 75d1477..18631f6 100644 --- a/testbench/yycc/string/parse.cpp +++ b/testbench/yycc/num/parse.cpp @@ -1,13 +1,13 @@ #include #include -#include +#include #include #include -#define PARSE ::yycc::string::parse +#define PARSE ::yycc::num::parse -namespace yycctest::string::parse { +namespace yycctest::num::parse { // These 2 test macros build string container via given string. // Check `try_parse` first, and then check `parse`. @@ -29,7 +29,7 @@ namespace yycctest::string::parse { EXPECT_ANY_THROW(PARSE::parse(cache_string, ##__VA_ARGS__)); \ } - TEST(StringParse, Common) { + TEST(NumParse, Common) { TEST_SUCCESS(i8, INT8_C(-61), "-61"); TEST_SUCCESS(u8, UINT8_C(200), "200"); TEST_SUCCESS(i16, INT16_C(6161), "6161"); @@ -46,17 +46,17 @@ namespace yycctest::string::parse { TEST_SUCCESS(bool, false, "false"); } - TEST(StringParse, Radix) { + TEST(NumParse, Radix) { TEST_SUCCESS(u32, UINT32_C(0xffff), "ffff", 16); TEST_SUCCESS(u32, UINT32_C(032), "032", 8); TEST_SUCCESS(u32, UINT32_C(0B1011), "1011", 2); } - TEST(StringParse, CaseInsensitive) { + TEST(NumParse, CaseInsensitive) { TEST_SUCCESS(bool, true, "tRUE"); } - TEST(StringParse, Overflow) { + TEST(NumParse, Overflow) { TEST_FAIL(i8, "6161"); TEST_FAIL(u8, "32800"); TEST_FAIL(i16, "61616161"); @@ -70,13 +70,13 @@ namespace yycctest::string::parse { TEST_FAIL(double, "1e114514"); } - TEST(StringParse, BadRadix) { + TEST(NumParse, BadRadix) { TEST_FAIL(u32, "fghj", 16); TEST_FAIL(u32, "099", 8); TEST_FAIL(u32, "12345", 2); } - TEST(StringParse, InvalidWords) { + TEST(NumParse, InvalidWords) { TEST_FAIL(u32, "hello, world!"); TEST_FAIL(bool, "hello, world!"); } diff --git a/testbench/yycc/string/stringify.cpp b/testbench/yycc/num/stringify.cpp similarity index 86% rename from testbench/yycc/string/stringify.cpp rename to testbench/yycc/num/stringify.cpp index fba5152..52850f6 100644 --- a/testbench/yycc/string/stringify.cpp +++ b/testbench/yycc/num/stringify.cpp @@ -1,13 +1,13 @@ #include #include +#include #include -#include #include -#define STRINGIFY ::yycc::string::stringify +#define STRINGIFY ::yycc::num::stringify -namespace yycctest::string::stringify { +namespace yycctest::num::stringify { #define TEST_SUCCESS(type_t, value, string_value, ...) \ { \ @@ -16,7 +16,7 @@ namespace yycctest::string::stringify { EXPECT_EQ(ret, YYCC_U8(string_value)); \ } - TEST(StringStringify, Common) { + TEST(NumStringify, Common) { TEST_SUCCESS(i8, INT8_C(-61), "-61"); TEST_SUCCESS(u8, UINT8_C(200), "200"); TEST_SUCCESS(i16, INT16_C(6161), "6161"); @@ -33,7 +33,7 @@ namespace yycctest::string::stringify { TEST_SUCCESS(bool, false, "false"); } - TEST(StringStringify, Radix) { + TEST(NumStringify, Radix) { TEST_SUCCESS(u32, UINT32_C(0xffff), "ffff", 16); TEST_SUCCESS(u32, UINT32_C(032), "32", 8); TEST_SUCCESS(u32, UINT32_C(0B1011), "1011", 2); diff --git a/testbench/yycc/rust/parse.cpp b/testbench/yycc/rust/num/parse.cpp similarity index 89% rename from testbench/yycc/rust/parse.cpp rename to testbench/yycc/rust/num/parse.cpp index 6d7f812..a90e0a6 100644 --- a/testbench/yycc/rust/parse.cpp +++ b/testbench/yycc/rust/num/parse.cpp @@ -1,10 +1,10 @@ #include #include -#include +#include #include -#define PARSE ::yycc::rust::parse +#define PARSE ::yycc::rust::num::parse namespace yycctest::rust::parse { @@ -30,7 +30,7 @@ namespace yycctest::rust::parse { EXPECT_FALSE(rv.has_value()); \ } - TEST(RustParse, Common) { + TEST(RustNumParse, Common) { TEST_SUCCESS(i8, INT8_C(-61), "-61"); TEST_SUCCESS(u8, UINT8_C(200), "200"); TEST_SUCCESS(i16, INT16_C(6161), "6161"); @@ -47,17 +47,17 @@ namespace yycctest::rust::parse { TEST_SUCCESS(bool, false, "false"); } - TEST(RustParse, Radix) { + TEST(RustNumParse, Radix) { TEST_SUCCESS(u32, UINT32_C(0xffff), "ffff", 16); TEST_SUCCESS(u32, UINT32_C(032), "032", 8); TEST_SUCCESS(u32, UINT32_C(0B1011), "1011", 2); } - TEST(RustParse, CaseInsensitive) { + TEST(RustNumParse, CaseInsensitive) { TEST_SUCCESS(bool, true, "tRUE"); } - TEST(RustParse, Overflow) { + TEST(RustNumParse, Overflow) { TEST_FAIL(i8, "6161"); TEST_FAIL(u8, "32800"); TEST_FAIL(i16, "61616161"); @@ -71,13 +71,13 @@ namespace yycctest::rust::parse { TEST_FAIL(double, "1e114514"); } - TEST(RustParse, BadRadix) { + TEST(RustNumParse, BadRadix) { TEST_FAIL(u32, "fghj", 16); TEST_FAIL(u32, "099", 8); TEST_FAIL(u32, "12345", 2); } - TEST(RustParse, InvalidWords) { + TEST(RustNumParse, InvalidWords) { TEST_FAIL(u32, "hello, world!"); TEST_FAIL(bool, "hello, world!"); } diff --git a/testbench/yycc/rust/stringify.cpp b/testbench/yycc/rust/num/stringify.cpp similarity index 88% rename from testbench/yycc/rust/stringify.cpp rename to testbench/yycc/rust/num/stringify.cpp index d2d54c7..4452d7a 100644 --- a/testbench/yycc/rust/stringify.cpp +++ b/testbench/yycc/rust/num/stringify.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include