Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <locale> |
| 11 | |
| 12 | // template <class charT> class ctype_byname; |
| 13 | |
| 14 | // const char* widen(const char* low, const char* high, charT* to) const; |
| 15 | |
| 16 | // I doubt this test is portable |
| 17 | |
Eric Fiselier | f523693 | 2014-08-21 02:03:01 +0000 | [diff] [blame] | 18 | // XFAIL: linux |
| 19 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | #include <locale> |
| 21 | #include <string> |
| 22 | #include <vector> |
| 23 | #include <cassert> |
| 24 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 25 | #include "platform_support.h" // locale name macros |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 26 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 27 | int main() |
| 28 | { |
| 29 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 30 | std::locale l(LOCALE_en_US_UTF_8); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 31 | { |
| 32 | typedef std::ctype<wchar_t> F; |
| 33 | const F& f = std::use_facet<F>(l); |
| 34 | std::string in(" A\x07.a1\x85"); |
| 35 | std::vector<wchar_t> v(in.size()); |
Howard Hinnant | 22a74dc | 2010-08-22 00:39:25 +0000 | [diff] [blame] | 36 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 37 | assert(f.widen(&in[0], in.data() + in.size(), v.data()) == in.data() + in.size()); |
| 38 | assert(v[0] == L' '); |
| 39 | assert(v[1] == L'A'); |
| 40 | assert(v[2] == L'\x07'); |
| 41 | assert(v[3] == L'.'); |
| 42 | assert(v[4] == L'a'); |
| 43 | assert(v[5] == L'1'); |
| 44 | assert(v[6] == wchar_t(-1)); |
| 45 | } |
| 46 | } |
| 47 | { |
| 48 | std::locale l("C"); |
| 49 | { |
| 50 | typedef std::ctype<wchar_t> F; |
| 51 | const F& f = std::use_facet<F>(l); |
| 52 | std::string in(" A\x07.a1\x85"); |
| 53 | std::vector<wchar_t> v(in.size()); |
Howard Hinnant | 22a74dc | 2010-08-22 00:39:25 +0000 | [diff] [blame] | 54 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | assert(f.widen(&in[0], in.data() + in.size(), v.data()) == in.data() + in.size()); |
| 56 | assert(v[0] == L' '); |
| 57 | assert(v[1] == L'A'); |
| 58 | assert(v[2] == L'\x07'); |
| 59 | assert(v[3] == L'.'); |
| 60 | assert(v[4] == L'a'); |
| 61 | assert(v[5] == L'1'); |
| 62 | assert(v[6] == wchar_t(133)); |
| 63 | } |
| 64 | } |
| 65 | } |