refactor: add document for some namespaces
This commit is contained in:
@ -11,11 +11,15 @@
|
||||
#define NS_YYCC_STRING_REINTERPRET ::yycc::string::reinterpret
|
||||
#define NS_YYCC_STRING_OP ::yycc::string::op
|
||||
|
||||
/**
|
||||
* @brief Provides string parsing utilities for converting strings to numeric and boolean values.
|
||||
* @details
|
||||
* This namespace contains functions for parsing strings into various numeric types (integer, floating point)
|
||||
* 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 {
|
||||
|
||||
// Developer Notes:
|
||||
// Reference: https://zh.cppreference.com/w/cpp/utility/from_chars
|
||||
|
||||
/// @private
|
||||
/// @brief The error kind when parsing string into number.
|
||||
enum class ParseError {
|
||||
@ -31,10 +35,11 @@ namespace yycc::string::parse {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @brief priv_parse
|
||||
* @param strl
|
||||
* @param fmt
|
||||
* @return
|
||||
* @brief Internal parsing function for floating point types
|
||||
* @tparam T Floating point type (float, double, etc)
|
||||
* @param strl The UTF-8 string view to parse
|
||||
* @param fmt The floating point format to use
|
||||
* @return ParseResult<T> containing either the parsed value or a ParseError
|
||||
*/
|
||||
template<typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>
|
||||
ParseResult<T> priv_parse(const NS_YYCC_STRING::u8string_view& strl, std::chars_format fmt) {
|
||||
@ -64,10 +69,11 @@ namespace yycc::string::parse {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @brief priv_parse
|
||||
* @param strl
|
||||
* @param base
|
||||
* @return
|
||||
* @brief Internal parsing function for integral types (except bool)
|
||||
* @tparam T Integral type (int, long, etc)
|
||||
* @param strl The UTF-8 string view to parse
|
||||
* @param base Numeric base (2-36)
|
||||
* @return ParseResult<T> containing either the parsed value or a ParseError
|
||||
*/
|
||||
template<typename T, std::enable_if_t<std::is_integral_v<T> && !std::is_same_v<T, bool>, int> = 0>
|
||||
ParseResult<T> priv_parse(const NS_YYCC_STRING::u8string_view& strl, int base) {
|
||||
@ -97,9 +103,10 @@ namespace yycc::string::parse {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @brief priv_parse
|
||||
* @param strl
|
||||
* @return
|
||||
* @brief Internal parsing function for boolean type
|
||||
* @tparam T Must be bool type
|
||||
* @param strl The UTF-8 string view to parse ("true" or "false", case insensitive)
|
||||
* @return ParseResult<bool> containing either the parsed value or a ParseError
|
||||
*/
|
||||
template<typename T, std::enable_if_t<std::is_same_v<T, bool>, int> = 0>
|
||||
ParseResult<T> priv_parse(const NS_YYCC_STRING::u8string_view& strl) {
|
||||
|
@ -3,20 +3,67 @@
|
||||
|
||||
#define NS_YYCC_STRING ::yycc::string
|
||||
|
||||
/**
|
||||
* @brief Provides utilities for reinterpretation between UTF-8 and ordinary string types.
|
||||
* @details
|
||||
* Please note that there is no encoding convertion happended in this namespace provided functions.
|
||||
* They just simply reinterpret one string to another string.
|
||||
* The validation of UTF8 string is guaranteed by user self.
|
||||
*/
|
||||
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).
|
||||
* @param src Source ordinary string
|
||||
* @return Pointer to UTF-8 encoded string
|
||||
*/
|
||||
const NS_YYCC_STRING::u8char* as_utf8(const char* src);
|
||||
/**
|
||||
* @brief Reinterpret ordinary C-string as an UTF-8 string (non-const version).
|
||||
* @param src Source ordinary string
|
||||
* @return Pointer to UTF-8 encoded string
|
||||
*/
|
||||
NS_YYCC_STRING::u8char* as_utf8(char* src);
|
||||
/**
|
||||
* @brief Reinterpret ordinary string view to copied UTF-8 string.
|
||||
* @param src Source ordinary string view
|
||||
* @return UTF-8 encoded string
|
||||
*/
|
||||
NS_YYCC_STRING::u8string as_utf8(const std::string_view& src);
|
||||
/**
|
||||
* @brief Reinterpret ordinary string view to UTF-8 string view.
|
||||
* @param src Source ordinary string view
|
||||
* @return UTF-8 encoded string view
|
||||
*/
|
||||
NS_YYCC_STRING::u8string_view as_utf8_view(const std::string_view& src);
|
||||
|
||||
/**
|
||||
* @brief Reinterpret UTF-8 C-string to ordinary string (const version).
|
||||
* @param src Source UTF-8 string
|
||||
* @return Pointer to ordinary string
|
||||
*/
|
||||
const char* as_ordinary(const NS_YYCC_STRING::u8char* src);
|
||||
/**
|
||||
* @brief Reinterpret UTF-8 C-string to ordinary string (non-const version).
|
||||
* @param src Source UTF-8 string
|
||||
* @return Pointer to ordinary string
|
||||
*/
|
||||
char* as_ordinary(NS_YYCC_STRING::u8char* src);
|
||||
/**
|
||||
* @brief Reinterpret UTF-8 string view to ordinary string.
|
||||
* @param src Source UTF-8 string view
|
||||
* @return Ordinary string
|
||||
*/
|
||||
std::string as_ordinary(const NS_YYCC_STRING::u8string_view& src);
|
||||
/**
|
||||
* @brief Reinterpret UTF-8 string view to ordinary string view
|
||||
* @param src Source UTF-8 string view
|
||||
* @return Ordinary string view
|
||||
*/
|
||||
std::string_view as_ordinary_view(const NS_YYCC_STRING::u8string_view& src);
|
||||
|
||||
}
|
||||
|
@ -9,15 +9,22 @@
|
||||
#define NS_YYCC_STRING ::yycc::string
|
||||
#define NS_YYCC_STRING_REINTERPRET ::yycc::string::reinterpret
|
||||
|
||||
/**
|
||||
* @brief Provides stringify utilities for converting numeric and boolean values to strings.
|
||||
* @details
|
||||
* This namespace contains functions for stringifying various numeric types (integer, floating point)
|
||||
* and boolean values into string. It uses \c std::to_chars internally for efficient stringify.
|
||||
* @remarks
|
||||
* 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 {
|
||||
|
||||
// Developer Notes:
|
||||
// Reference: https://en.cppreference.com/w/cpp/utility/to_chars
|
||||
// Default float precision = 6 is gotten from: https://en.cppreference.com/w/c/io/fprintf
|
||||
|
||||
/// @private
|
||||
/// @brief Size of the internal buffer used for string conversion.
|
||||
inline constexpr size_t STRINGIFY_BUFFER_SIZE = 64u;
|
||||
/// @private
|
||||
/// @brief Type alias for the buffer used in string conversion.
|
||||
using StringifyBuffer = std::array<NS_YYCC_STRING::u8char, STRINGIFY_BUFFER_SIZE>;
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user