blob: b46ae32237b7dd0752fc708f258b153c27bb8831 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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 Fiselierf5236932014-08-21 02:03:01 +000018// XFAIL: linux
19
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000020#include <locale>
21#include <string>
22#include <vector>
23#include <cassert>
24
Marshall Clow83e2c4d2013-01-05 03:21:01 +000025#include "platform_support.h" // locale name macros
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000026
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000027int main()
28{
29 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000030 std::locale l(LOCALE_en_US_UTF_8);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000031 {
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 Hinnant22a74dc2010-08-22 00:39:25 +000036
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000037 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 Hinnant22a74dc2010-08-22 00:39:25 +000054
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000055 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}