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 // <locale> 11 12 // class time_get_byname<charT, InputIterator> 13 14 // iter_type 15 // get_weekday(iter_type s, iter_type end, ios_base& str, 16 // ios_base::iostate& err, tm* t) const; 17 18 #include <locale> 19 #include <cassert> 20 #include "test_iterators.h" 21 22 #include "platform_support.h" // locale name macros 23 24 typedef input_iterator<const char*> I; 25 26 typedef std::time_get_byname<char, I> F; 27 28 class my_facet 29 : public F 30 { 31 public: 32 explicit my_facet(const std::string& nm, std::size_t refs = 0) 33 : F(nm, refs) {} 34 }; 35 36 int main() 37 { 38 std::ios ios(0); 39 std::ios_base::iostate err; 40 std::tm t; 41 { 42 const my_facet f(LOCALE_en_US_UTF_8, 1); 43 const char in[] = "Monday"; 44 err = std::ios_base::goodbit; 45 t = std::tm(); 46 I i = f.get_weekday(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); 47 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); 48 assert(t.tm_wday == 1); 49 assert(err == std::ios_base::eofbit); 50 } 51 { 52 const my_facet f(LOCALE_fr_FR_UTF_8, 1); 53 const char in[] = "Lundi"; 54 err = std::ios_base::goodbit; 55 t = std::tm(); 56 I i = f.get_weekday(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); 57 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); 58 assert(t.tm_wday == 1); 59 assert(err == std::ios_base::eofbit); 60 } 61 { 62 const my_facet f(LOCALE_ru_RU_UTF_8, 1); 63 const char in[] = "\xD0\xBF\xD0\xBE\xD0\xBD\xD0\xB5" 64 "\xD0\xB4\xD0\xB5\xD0\xBB\xD1\x8C" 65 "\xD0\xBD\xD0\xB8\xD0\xBA"; 66 err = std::ios_base::goodbit; 67 t = std::tm(); 68 I i = f.get_weekday(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); 69 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); 70 assert(t.tm_wday == 1); 71 assert(err == std::ios_base::eofbit); 72 } 73 { 74 const my_facet f(LOCALE_zh_CN_UTF_8, 1); 75 const char in[] = "\xE6\x98\x9F\xE6\x9C\x9F\xE4\xB8\x80"; 76 err = std::ios_base::goodbit; 77 t = std::tm(); 78 I i = f.get_weekday(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); 79 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); 80 assert(t.tm_wday == 1); 81 assert(err == std::ios_base::eofbit); 82 } 83 } 84