libcmo21/LibCmo/VTEncoding.hpp

67 lines
1.8 KiB
C++
Raw Normal View History

2023-02-10 16:17:17 +08:00
#pragma once
2023-02-11 15:29:51 +08:00
#include "VTUtils.hpp"
2023-02-10 16:17:17 +08:00
#include <string>
2023-02-25 22:58:28 +08:00
#include <filesystem>
2023-02-10 16:17:17 +08:00
#if defined(LIBCMO_OS_WIN32)
#include <Windows.h>
2023-02-12 21:03:36 +08:00
#include <fileapi.h>
2023-02-10 16:17:17 +08:00
#else
#include <iconv.h>
#endif
2023-02-26 21:48:03 +08:00
namespace LibCmo::EncodingHelper {
2023-02-10 16:17:17 +08:00
#pragma region assist functions
#if defined(LIBCMO_OS_WIN32)
2023-02-26 21:48:03 +08:00
bool GetWindowsCodePage(const char* u8_encoding_spec, UINT* result);
2023-02-10 16:17:17 +08:00
2023-02-26 21:48:03 +08:00
bool WcharToChar(const wchar_t* src, std::string& dest, UINT codepage);
bool WcharToChar(std::wstring& src, std::string& dest, UINT codepage);
2023-02-10 16:17:17 +08:00
2023-02-26 21:48:03 +08:00
bool CharToWchar(const char* src, std::wstring& dest, UINT codepage);
bool CharToWchar(std::string& src, std::wstring& dest, UINT codepage);
2023-02-10 16:17:17 +08:00
2023-02-26 21:48:03 +08:00
bool CharToChar(const char* src, std::string& dest, UINT src_codepage, UINT dest_codepage);
bool CharToChar(std::string& src, std::string& dest, UINT src_codepage, UINT dest_codepage);
2023-02-25 22:58:28 +08:00
2023-02-11 15:29:51 +08:00
#else
2023-03-01 15:51:56 +08:00
bool DoIconv(const char* enc_from, const char* enc_to, std::string& str_from, std::string& str_to);
2023-02-10 16:17:17 +08:00
#endif
#pragma endregion
#pragma region core functions
#if defined(LIBCMO_OS_WIN32)
2023-03-01 15:51:56 +08:00
// Token is the ticket for using encoding functions.
// It should be created by "GenerateEncodingToken" and free by "DestroyEncodingToken".
2023-02-26 21:48:03 +08:00
using ENCODING_TOKEN = UINT*;
2023-03-01 15:51:56 +08:00
constexpr const ENCODING_TOKEN ENCODING_TOKEN_DEFAULT = nullptr;
#else
using ENCODING_TOKEN = char*;
constexpr const ENCODING_TOKEN ENCODING_TOKEN_DEFAULT = nullptr;
#endif
2023-02-25 22:58:28 +08:00
2023-02-26 21:48:03 +08:00
ENCODING_TOKEN CreateEncodingToken(std::string& token_string);
void DestroyEncodingToken(ENCODING_TOKEN token);
2023-02-25 22:58:28 +08:00
2023-02-26 21:48:03 +08:00
void GetUtf8VirtoolsName(std::string& native_name, std::string& u8_name, ENCODING_TOKEN token);
void GetNativeVirtoolsName(std::string& u8_name, std::string& native_name, ENCODING_TOKEN token);
2023-02-25 22:58:28 +08:00
2023-02-26 21:48:03 +08:00
void SetStdPathFromU8Path(std::filesystem::path& stdpath, const char* u8_path);
FILE* OpenStdPathFile(std::filesystem::path& u8_filepath, bool is_read);
2023-02-10 16:17:17 +08:00
#pragma endregion
}