Home | History | Annotate | Download | only in conversions.string
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <locale>
     11 
     12 // wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
     13 
     14 // wstring_convert(const byte_string& byte_err,
     15 //                 const wide_string& wide_err = wide_string());
     16 
     17 #include <locale>
     18 #include <codecvt>
     19 #include <cassert>
     20 
     21 int main()
     22 {
     23     typedef std::codecvt_utf8<wchar_t> Codecvt;
     24     typedef std::wstring_convert<Codecvt> Myconv;
     25 #if _LIBCPP_STD_VER > 11
     26     static_assert(!std::is_convertible<std::string, Myconv>::value, "");
     27     static_assert( std::is_constructible<Myconv, std::string>::value, "");
     28 #endif
     29     {
     30         Myconv myconv;
     31         try
     32         {
     33             myconv.to_bytes(L"\xDA83");
     34             assert(false);
     35         }
     36         catch (const std::range_error&)
     37         {
     38         }
     39         try
     40         {
     41             myconv.from_bytes('\xA5');
     42             assert(false);
     43         }
     44         catch (const std::range_error&)
     45         {
     46         }
     47     }
     48     {
     49         Myconv myconv("byte error");
     50         std::string bs = myconv.to_bytes(L"\xDA83");
     51         assert(bs == "byte error");
     52         try
     53         {
     54             myconv.from_bytes('\xA5');
     55             assert(false);
     56         }
     57         catch (const std::range_error&)
     58         {
     59         }
     60     }
     61     {
     62         Myconv myconv("byte error", L"wide error");
     63         std::string bs = myconv.to_bytes(L"\xDA83");
     64         assert(bs == "byte error");
     65         std::wstring ws = myconv.from_bytes('\xA5');
     66         assert(ws == L"wide error");
     67     }
     68 }
     69