to_bytes.pass.cpp revision d23b464e21648e252d5ae501b2db2e93dc02b1f7
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <locale> 11 12// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc> 13 14// byte_string to_bytes(Elem wchar); 15// byte_string to_bytes(const Elem* wptr); 16// byte_string to_bytes(const wide_string& wstr); 17// byte_string to_bytes(const Elem* first, const Elem* last); 18 19#include <locale> 20#include <codecvt> 21#include <cassert> 22 23int main() 24{ 25 { 26 std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv; 27 std::wstring ws(1, L'\x40003'); 28 std::string bs = myconv.to_bytes(ws[0]); 29 assert(bs == "\xF1\x80\x80\x83"); 30 bs = myconv.to_bytes(ws.c_str()); 31 assert(bs == "\xF1\x80\x80\x83"); 32 bs = myconv.to_bytes(ws); 33 assert(bs == "\xF1\x80\x80\x83"); 34 bs = myconv.to_bytes(ws.data(), ws.data() + ws.size()); 35 assert(bs == "\xF1\x80\x80\x83"); 36 } 37} 38