refactor: write iconv.

- write iconv encoding (not finished).
- rename united_codec to pycodec.
This commit is contained in:
2025-07-15 16:17:59 +08:00
parent 3605151caf
commit c102964703
11 changed files with 292 additions and 304 deletions

View File

@ -1,7 +1,10 @@
#pragma once
#include "../macro/os_detector.hpp"
#include "../string.hpp"
#if YYCC_OS == YYCC_OS_WINDOWS
#include "../patch/expected.hpp"
#include "../string.hpp"
#include <cstdint>
#define NS_YYCC_STRING ::yycc::string
@ -9,14 +12,12 @@
namespace yycc::encoding::windows {
#if YYCC_OS == YYCC_OS_WINDOWS
using CodePage = uint32_t;
/// @private
enum class ConvError {
TooLargeLength, ///< The length of given string is too large exceeding the maximum capacity of Win32 function.
NoDesiredSize, ///< Can not compute the desired size of result string.
NoDesiredSize, ///< Can not compute the desired size of result string.
BadWrittenSize, ///< The size of written data is not matched with expected size.
};
@ -34,47 +35,39 @@ namespace yycc::encoding::windows {
bool to_wchar(const std::string_view& src, std::wstring& dst, CodePage code_page);
std::wstring to_wchar(const std::string_view& src, CodePage code_page);
// YYC MARK:
// Following functions are basically the alias of above functions.
// Char -> Char
ConvResult<std::string> priv_to_char(const std::string_view& src,
CodePage src_code_page,
CodePage dst_code_page);
bool to_char(const std::string_view& src,
std::string& dst,
CodePage src_code_page,
CodePage dst_code_page);
// This is the combination of "WChar -> Char" and "Char -> WChar"
ConvResult<std::string> priv_to_char(const std::string_view& src, CodePage src_code_page, CodePage dst_code_page);
bool to_char(const std::string_view& src, std::string& dst, CodePage src_code_page, CodePage dst_code_page);
std::string to_char(const std::string_view& src, CodePage src_code_page, CodePage dst_code_page);
// YYC MARK:
// Following functions are basically the specialized UTF8 functions.
// WChar -> UTF8
// This is the specialization of "WChar -> Char"
ConvResult<NS_YYCC_STRING::u8string> priv_to_utf8(const std::wstring_view& src);
bool to_utf8(const std::wstring_view& src, NS_YYCC_STRING::u8string& dst);
NS_YYCC_STRING::u8string to_utf8(const std::wstring_view& src);
// UTF8 -> WChar
// This is the specialization of "Char -> WChar"
ConvResult<std::wstring> priv_to_wchar(const NS_YYCC_STRING::u8string_view& src);
bool to_wchar(const NS_YYCC_STRING::u8string_view& src, std::wstring& dst);
std::wstring to_wchar(const NS_YYCC_STRING::u8string_view& src);
// Char -> UTF8
ConvResult<NS_YYCC_STRING::u8string> priv_to_utf8(const std::string_view& src,
CodePage code_page);
// This is the specialization of "Char -> Char"
ConvResult<NS_YYCC_STRING::u8string> priv_to_utf8(const std::string_view& src, CodePage code_page);
bool to_utf8(const std::string_view& src, NS_YYCC_STRING::u8string& dst, CodePage code_page);
NS_YYCC_STRING::u8string to_utf8(const std::string_view& src, CodePage code_page);
// UTF8 -> Char
ConvResult<std::string> priv_to_char(const NS_YYCC_STRING::u8string_view& src,
CodePage code_page);
// This is the specialization of "Char -> Char"
ConvResult<std::string> priv_to_char(const NS_YYCC_STRING::u8string_view& src, CodePage code_page);
bool to_char(const NS_YYCC_STRING::u8string_view& src, std::string& dst, CodePage code_page);
std::string to_char(const NS_YYCC_STRING::u8string_view& src, CodePage code_page);
#endif
} // namespace yycc::encoding::windows
#undef NS_YYCC_PATCH_EXPECTED
#undef NS_YYCC_STRING
#endif