Files
AronaCore/core/misc/core_str.h
2024-07-17 19:18:07 +08:00

37 lines
923 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
// 定义 TCHAR 类型
#ifdef UNICODE
using char_t = wchar_t;
#define TEXT(x) L##x
#else
using char_t = char;
#define TEXT(x) x
#endif
inline auto ANSI_TO_TCHAR(const char* ansi_str) -> const char_t* {
#ifdef UNICODE
// 如果 TCHAR 是 wchar_t需要进行转换
size_t len = strlen(ansiStr) + 1;
std::vector<wchar_t> wstr(len);
mbstowcs(wstr.data(), ansiStr, len);
return wstr.data();
#else
// 如果 TCHAR 是 char直接返回原始字符串
return ansi_str;
#endif
}
inline auto TCHAR_TO_ANSI(const char_t* tchar_str) -> const char* {
#ifdef UNICODE
// 如果 TCHAR 是 wchar_t需要进行转换
size_t len = wcslen(tcharStr) + 1;
std::vector<char> ansiStr(len);
wcstombs(ansiStr.data(), tcharStr, len);
return ansiStr.data();
#else
// 如果 TCHAR 是 char直接返回原始字符串
return tchar_str;
#endif
}