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