12#if defined(__BORLANDC__)
27 int utf16_to_utf8(DWORD dwFlags, LPCWSTR lpWideCharStr,
int cchWideChar, LPSTR lpMultiByteStr,
int cbMultiByte)
28 {
return WideCharToMultiByte(CP_UTF8, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr, cbMultiByte,
nullptr,
nullptr);}
33 int utf8_to_utf16(DWORD dwFlags, LPCSTR lpMultiByteStr,
int cbMultiByte, LPWSTR lpWideCharStr,
int cchWideChar)
34 {
return MultiByteToWideChar(CP_UTF8, dwFlags, lpMultiByteStr, cbMultiByte, lpWideCharStr, cchWideChar);}
40 template <
class Result,
class Source,
class Converter>
41 Result convert(
const Source& source, Converter*
const converter,
const DWORD flags = 0)
49 int n = (*converter)(flags, &source[0], -1,
nullptr, 0);
51 WARN(n == 0,
_T(
"String conversion sizing failed, GetLastError() == ") << GetLastError());
58 int r = (*converter)(flags, &source[0], -1, &result[0], n);
60 WARN(r == 0,
_T(
"String conversion failed, GetLastError() == ") << GetLastError());
61 result.erase(r > 0 ? r - 1 : 0);
72 typedef std::string narrow_string;
73 typedef std::wstring wide_string;
78 inline narrow_string convert_to_narrow_string(
const wide_string& s_utf16)
80 return convert<narrow_string>(s_utf16, utf16_to_utf8);
86 inline const narrow_string& convert_to_narrow_string(
const narrow_string& s)
95 template <
class Result>
96 struct ConverterFromNarrowString
98 inline Result operator () (
const narrow_string& s_utf8)
99 {
return convert<Result>(s_utf8, utf8_to_utf16, MB_ERR_INVALID_CHARS);}
106 struct ConverterFromNarrowString<narrow_string>
108 inline const narrow_string& operator () (
const narrow_string& s)
122 : std::exception(),
str(convert_to_narrow_string(msg))
129: std::exception(),
str(src.
str)
171 return ConverterFromNarrowString<tstring>()(
str);
Diagnostic macros for assertions and tracing.
#define WARN(condition, message)
TXBase(const tstring &msg)
Calls the xmsg class's constructor that takes a string parameter and initializes xmsg with the value ...
const char * what() const noexcept
virtual TXBase * Clone()
Makes a copy of the exception object.
static void Raise(const tstring &msg)
Constructs a TXBase exception from scratch, and throws it.
virtual void Throw()
Throws the exception object.
TXBase &_RTLENTRY operator=(const TXBase &src)
Base exception support for framework exceptions.
Object Windows Library (OWLNext Core).