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 // REQUIRES: locale.en_US.UTF-8
11 // REQUIRES: locale.fr_FR.UTF-8
12 // REQUIRES: locale.ru_RU.UTF-8
13 // REQUIRES: locale.zh_CN.UTF-8
14
15 // <locale>
16
17 // class time_get_byname<charT, InputIterator>
18
19 // iter_type
20 // get_monthname(iter_type s, iter_type end, ios_base& str,
21 // ios_base::iostate& err, tm* t) const;
22
23 #include <locale>
24 #include <cassert>
25 #include "test_iterators.h"
26
27 #include "platform_support.h" // locale name macros
28
29 typedef input_iterator<const wchar_t*> I;
30
31 typedef std::time_get_byname<wchar_t, I> F;
32
33 class my_facet
34 : public F
35 {
36 public:
my_facet(const std::string & nm,std::size_t refs=0)37 explicit my_facet(const std::string& nm, std::size_t refs = 0)
38 : F(nm, refs) {}
39 };
40
41 typedef std::time_put_byname<wchar_t, wchar_t*> F2;
42 class my_facet2
43 : public F2
44 {
45 public:
my_facet2(const std::string & nm,std::size_t refs=0)46 explicit my_facet2(const std::string& nm, std::size_t refs = 0)
47 : F2(nm, refs) {}
48 };
49
main()50 int main()
51 {
52 std::ios ios(0);
53 std::ios_base::iostate err;
54 std::tm t;
55 {
56 const my_facet f(LOCALE_en_US_UTF_8, 1);
57 const wchar_t in[] = L"June";
58 err = std::ios_base::goodbit;
59 t = std::tm();
60 I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
61 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
62 assert(t.tm_mon == 5);
63 assert(err == std::ios_base::eofbit);
64 }
65 {
66 const my_facet f(LOCALE_fr_FR_UTF_8, 1);
67 const wchar_t in[] = L"juin";
68 err = std::ios_base::goodbit;
69 t = std::tm();
70 I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
71 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
72 assert(t.tm_mon == 5);
73 assert(err == std::ios_base::eofbit);
74 }
75 {
76 const my_facet f(LOCALE_ru_RU_UTF_8, 1);
77 const wchar_t in[] = L"\x438\x44E\x43D\x44F";
78 err = std::ios_base::goodbit;
79 t = std::tm();
80 I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
81 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
82 assert(t.tm_mon == 5);
83 assert(err == std::ios_base::eofbit);
84 }
85 {
86 const my_facet f(LOCALE_zh_CN_UTF_8, 1);
87 const wchar_t in[] = L"\x516D\x6708";
88 err = std::ios_base::goodbit;
89 t = std::tm();
90 I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
91 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
92 assert(t.tm_mon == 5);
93 assert(err == std::ios_base::eofbit);
94 }
95 }
96