refactor: re-place files into correct position according to namespace hierarchy

This commit is contained in:
2025-06-30 08:45:18 +08:00
parent e166dc41ac
commit 3030a67ca3
17 changed files with 50 additions and 50 deletions

View File

@ -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

View File

View File

View File

View File

View File

View File

View File

View File

@ -1,7 +1,7 @@
#pragma once
#include "../string.hpp"
#include "op.hpp"
#include "reinterpret.hpp"
#include "../string/op.hpp"
#include "../string/reinterpret.hpp"
#include <charconv>
#include <stdexcept>
#include <type_traits>
@ -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.

View File

@ -1,6 +1,6 @@
#pragma once
#include "../string.hpp"
#include "reinterpret.hpp"
#include "../string/reinterpret.hpp"
#include <array>
#include <charconv>
#include <stdexcept>
@ -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.

View File

@ -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<typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>
Result<T> parse(const NS_YYCC_STRING::u8string_view& strl,
std::chars_format fmt = std::chars_format::general) {
auto rv = NS_YYCC_STRING_PARSE::priv_parse<T>(strl, fmt);
auto rv = NS_YYCC_NUM_PARSE::priv_parse<T>(strl, fmt);
if (const auto* ptr = std::get_if<T>(&rv)) {
return NS_YYCC_RUST_RESULT::Ok<Result<T>>(*ptr);
@ -58,7 +58,7 @@ namespace yycc::rust::parse {
*/
template<typename T, std::enable_if_t<std::is_integral_v<T> && !std::is_same_v<T, bool>, int> = 0>
Result<T> parse(const NS_YYCC_STRING::u8string_view& strl, int base = 10) {
auto rv = NS_YYCC_STRING_PARSE::priv_parse<T>(strl, base);
auto rv = NS_YYCC_NUM_PARSE::priv_parse<T>(strl, base);
if (const auto* ptr = std::get_if<T>(&rv)) {
return NS_YYCC_RUST_RESULT::Ok<Result<T>>(*ptr);
@ -78,7 +78,7 @@ namespace yycc::rust::parse {
*/
template<typename T, std::enable_if_t<std::is_same_v<T, bool>, int> = 0>
Result<T> parse(const NS_YYCC_STRING::u8string_view& strl) {
auto rv = NS_YYCC_STRING_PARSE::priv_parse<T>(strl);
auto rv = NS_YYCC_NUM_PARSE::priv_parse<T>(strl);
if (const auto* ptr = std::get_if<T>(&rv)) {
return NS_YYCC_RUST_RESULT::Ok<Result<T>>(*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

View File

@ -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

View File

@ -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

View File

@ -1,13 +1,13 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/string/parse.hpp>
#include <yycc/num/parse.hpp>
#include <yycc/string/reinterpret.hpp>
#include <yycc/prelude/rust.hpp>
#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<type_t>(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!");
}

View File

@ -1,13 +1,13 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/num/stringify.hpp>
#include <yycc/string/reinterpret.hpp>
#include <yycc/string/stringify.hpp>
#include <yycc/prelude/rust.hpp>
#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);

View File

@ -1,10 +1,10 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/rust/parse.hpp>
#include <yycc/rust/num/parse.hpp>
#include <yycc/prelude/rust.hpp>
#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!");
}

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/rust/stringify.hpp>
#include <yycc/rust/num/stringify.hpp>
#include <yycc/prelude/rust.hpp>