47#if LASS_HAVE_MULTIBYTETOWIDECHAR
48# define WIN32_LEAN_AND_MEAN
65#if LASS_HAVE_WCHAR_SUPPORT
67std::wstring utf8ToWchar(
const std::string& utf8)
70 utf8ToWchar(utf8.data(), utf8.length(), wide);
74std::wstring utf8ToWchar(
const char* utf8)
77 utf8ToWchar(utf8, ::strlen(utf8), wide);
81std::wstring utf8ToWchar(
const char* utf8,
size_t length)
84 utf8ToWchar(utf8, length, wide);
88std::string wcharToUtf8(
const std::wstring& wide)
91 wcharToUtf8(wide.data(), wide.length(), utf8);
95std::string wcharToUtf8(
const wchar_t* wide)
98 wcharToUtf8(wide, ::wcslen(wide), utf8);
102std::string wcharToUtf8(
const wchar_t* wide,
size_t length)
105 wcharToUtf8(wide, length, utf8);
111# if LASS_HAVE_MULTIBYTETOWIDECHAR
113LASS_META_ASSERT(
sizeof(
wchar_t) ==
sizeof(WCHAR), wchar_t_should_be_of_same_size_as_WCHAR );
115void utf8ToWchar(
const char* utf8,
size_t length, std::wstring &wide)
122 const int utf8Length = num::numCast<int>(length);
123 const int wideLength = LASS_ENFORCE_WINAPI(MultiByteToWideChar(CP_UTF8, 0, utf8, utf8Length, 0, 0));
124 wide.resize(num::numCast<size_t>(wideLength));
125 LASS_ENFORCE_WINAPI(MultiByteToWideChar(CP_UTF8, 0, utf8, utf8Length, &wide[0], wideLength));
128void wcharToUtf8(
const wchar_t* wide,
size_t length, std::string &utf8)
135 const int wideLength = num::numCast<int>(length);
136 const int utf8Length = LASS_ENFORCE_WINAPI(WideCharToMultiByte(CP_UTF8, 0, wide, wideLength, 0, 0, NULL, NULL));
137 utf8.resize(num::numCast<size_t>(utf8Length));
138 LASS_ENFORCE_WINAPI(WideCharToMultiByte(CP_UTF8, 0, wide, wideLength, &utf8[0], utf8Length, NULL, NULL));
141# elif LASS_HAVE_ICONV
145 LASS_META_ASSERT(
sizeof(
wchar_t) == 2 ||
sizeof(
wchar_t) == 4, expects_wchar_t_to_be_16_or_32_bit);
150 Converter(
const char* tocode,
const char* fromcode)
152 handle_ = LASS_ENFORCE_CLIB_EX( iconv_open(tocode, fromcode), (iconv_t)-1 );
156 iconv_close(handle_);
158 template <
typename string_type>
159 void convert(
const char* in,
size_t inBytes, string_type &result)
161 typedef typename string_type::value_type char_type;
162 iconv(handle_, 0, 0, 0, 0);
165# if LASS_HAVE_ICONV_CONST_CHAR
166 const char* pIn =
in;
168 char* pIn =
const_cast<char*
>(
in);
173 char* pOut = buffer_;
174 size_t outLeft = bufsize_;
176 if (iconv(handle_, &pIn, &inBytes, &pOut, &outLeft) == (
size_t)-1)
180 const size_t bytes = bufsize_ - outLeft;
181 LASS_ASSERT(bytes %
sizeof(char_type) == 0);
182 result.append(
reinterpret_cast<char_type*
>( buffer_ ), bytes /
sizeof(char_type) );
186 LASS_THROW(
"BLABLA");
191 const size_t bytes = bufsize_ - outLeft;
192 LASS_ASSERT(bytes %
sizeof(char_type) == 0 && (bytes /
sizeof(char_type)) > 0);
193 result.append(
reinterpret_cast<char_type*
>( buffer_ ), bytes /
sizeof(char_type) - 1 );
198 enum { bufsize_ = 1024 };
200 char buffer_[bufsize_];
203 typedef ThreadLocalPtr<Converter> TConverterPtr;
205 const char* wchar_encoding =
206# if LASS_HAVE_WCHAR_T == 2
207# if LASS_HAVE_BIG_ENDIAN
212# elif LASS_HAVE_WCHAR_T == 4
213# if LASS_HAVE_BIG_ENDIAN
219# error "[LASS BUILD MSG] unsupported wchar_t size"
223void utf8ToWchar(
const char* utf8,
size_t length, std::wstring &wide)
225 static TConverterPtr converter;
228 std::unique_ptr<Converter> p(
new Converter(wchar_encoding,
"UTF-8"));
229 converter.reset(std::move(p));
231 converter->convert( utf8, length + 1, wide );
234void wcharToUtf8(
const wchar_t* wide,
size_t length, std::string &utf8)
236 static TConverterPtr converter;
239 std::unique_ptr<Converter> p(
new Converter(
"UTF-8", wchar_encoding));
240 converter.reset(std::move(p));
242 converter->convert(
reinterpret_cast<const char*
>(wide),
sizeof(
wchar_t) * (length + 1), utf8 );
247# pragma LASS_NOTE("no wchar_t support implemented, it will be unavailable.")
ColorRGBA in(const ColorRGBA &a, const ColorRGBA &b)
part of a inside b.
general utility, debug facilities, ...
Library for Assembled Shared Sources.