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<charT, InputIterator> 13 14 // iter_type 15 // get(iter_type s, iter_type end, ios_base& f, ios_base::iostate& err, tm *t, 16 // const char_type *fmt, const char_type *fmtend) const; 17 18 #include <locale> 19 #include <cassert> 20 #include "test_iterators.h" 21 22 typedef input_iterator<const char*> I; 23 24 typedef std::time_get<char, I> F; 25 26 class my_facet 27 : public F 28 { 29 public: 30 explicit my_facet(std::size_t refs = 0) 31 : F(refs) {} 32 }; 33 34 int main() 35 { 36 const my_facet f(1); 37 std::ios ios(0); 38 std::ios_base::iostate err; 39 std::tm t; 40 { 41 const char in[] = "2009 May 9, 10:27pm"; 42 const char fmt[] = "%Y %b %d, %I:%M%p"; 43 err = std::ios_base::goodbit; 44 t = std::tm(); 45 I i = f.get(I(in), I(in+sizeof(in)-1), ios, err, &t, fmt, fmt+sizeof(fmt)-1); 46 assert(i.base() == in+sizeof(in)-1); 47 assert(t.tm_year == 109); 48 assert(t.tm_mon == 4); 49 assert(t.tm_mday == 9); 50 assert(t.tm_hour == 22); 51 assert(t.tm_min == 27); 52 assert(err == std::ios_base::eofbit); 53 } 54 { 55 const char in[] = "10:27PM May 9, 2009"; 56 const char fmt[] = "%I:%M%p %b %d, %Y"; 57 err = std::ios_base::goodbit; 58 t = std::tm(); 59 I i = f.get(I(in), I(in+sizeof(in)-1), ios, err, &t, fmt, fmt+sizeof(fmt)-1); 60 assert(i.base() == in+sizeof(in)-1); 61 assert(t.tm_year == 109); 62 assert(t.tm_mon == 4); 63 assert(t.tm_mday == 9); 64 assert(t.tm_hour == 22); 65 assert(t.tm_min == 27); 66 assert(err == std::ios_base::eofbit); 67 } 68 } 69