Files
UNSWebServerCore_LinuxSO/utextcodec/UTextCodec.h
T
2026-06-30 17:49:51 +08:00

41 lines
1.2 KiB
C++

#pragma once
#include <string>
#ifdef _WIN32
#include <Windows.h>
#if defined(UTEXTCODEC_EXPORTS)
#define UTEXTCODEC_EXPORT __declspec(dllexport)
#else
#define UTEXTCODEC_EXPORT __declspec(dllimport)
#endif
#else
#define UTEXTCODEC_EXPORT __attribute__((visibility("default")))
#endif
class UTEXTCODEC_EXPORT UTextCodec
{
public:
// UTF-8 ⇄ UTF-16 (wstring)
static std::wstring UTF8to16(const std::string& utf8);
static std::string UTF16to8(const std::wstring& wstr);
// UTF-8 ⇄ UTF-32
static std::u32string UTF8to32(const std::string& utf8);
static std::string UTF32to8(const std::u32string& u32str);
// wstring ⇄ u32string
static std::u32string WtoUTF32(const std::wstring& wstr);
static std::wstring UTF32toW(const std::u32string& u32str);
// wstring ⇄ string
static std::wstring StoW(const std::string& str);
static std::string WtoS(const std::wstring& wstr);
#ifdef _WIN32
// Windows ANSI ⇄ UTF-16 (wstring)
static std::wstring AtoW(const std::string& ansi, UINT codePage = CP_ACP);
static std::string WtoA(const std::wstring& wstr, UINT codePage = CP_ACP);
#endif
static std::string DetectEncoding();
};