Howard Hinnant | d23b464 | 2010-05-31 20:58:54 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | d23b464 | 2010-05-31 20:58:54 +0000 | [diff] [blame] | 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; |
Marshall Clow | 83179a7 | 2013-08-27 20:18:59 +0000 | [diff] [blame] | 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 |
Howard Hinnant | d23b464 | 2010-05-31 20:58:54 +0000 | [diff] [blame] | 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 | } |