//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // wstring_convert // byte_string to_bytes(Elem wchar); // byte_string to_bytes(const Elem* wptr); // byte_string to_bytes(const wide_string& wstr); // byte_string to_bytes(const Elem* first, const Elem* last); #include #include #include template struct TestHelper; template struct TestHelper { static void test(); }; template struct TestHelper { static void test(); }; template void TestHelper::test() { static_assert((std::is_same::value), ""); { std::wstring_convert > myconv; std::wstring ws(1, CharT(0x1005)); std::string bs = myconv.to_bytes(ws[0]); assert(bs == "\xE1\x80\x85\x00"); bs = myconv.to_bytes(ws.c_str()); assert(bs == "\xE1\x80\x85\x00"); bs = myconv.to_bytes(ws); assert(bs == "\xE1\x80\x85\x00"); bs = myconv.to_bytes(ws.data(), ws.data() + ws.size()); assert(bs == "\xE1\x80\x85\x00"); bs = myconv.to_bytes(L""); assert(bs.size() == 0); } } template void TestHelper::test() { static_assert((std::is_same::value), ""); { std::wstring_convert > myconv; std::wstring ws(1, CharT(0x40003)); std::string bs = myconv.to_bytes(ws[0]); assert(bs == "\xF1\x80\x80\x83"); bs = myconv.to_bytes(ws.c_str()); assert(bs == "\xF1\x80\x80\x83"); bs = myconv.to_bytes(ws); assert(bs == "\xF1\x80\x80\x83"); bs = myconv.to_bytes(ws.data(), ws.data() + ws.size()); assert(bs == "\xF1\x80\x80\x83"); bs = myconv.to_bytes(L""); assert(bs.size() == 0); } } int main() { TestHelper::test(); }