• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  // <iomanip>
11  
12  // template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt);
13  
14  #include <iomanip>
15  #include <cassert>
16  
17  #include "platform_support.h" // locale name macros
18  
19  template <class CharT>
20  class testbuf
21      : public std::basic_streambuf<CharT>
22  {
23      typedef std::basic_streambuf<CharT> base;
24      std::basic_string<CharT> str_;
25  public:
testbuf()26      testbuf()
27      {
28      }
29  
str() const30      std::basic_string<CharT> str() const
31          {return std::basic_string<CharT>(base::pbase(), base::pptr());}
32  
33  protected:
34  
35      virtual typename base::int_type
overflow(typename base::int_type __c=base::traits_type::eof ())36          overflow(typename base::int_type __c = base::traits_type::eof())
37          {
38              if (__c != base::traits_type::eof())
39              {
40                  int n = str_.size();
41                  str_.push_back(__c);
42                  str_.resize(str_.capacity());
43                  base::setp(const_cast<CharT*>(str_.data()),
44                             const_cast<CharT*>(str_.data() + str_.size()));
45                  base::pbump(n+1);
46              }
47              return __c;
48          }
49  };
50  
main()51  int main()
52  {
53      {
54          testbuf<char> sb;
55          std::ostream os(&sb);
56          os.imbue(std::locale(LOCALE_en_US_UTF_8));
57          std::tm t = {0};
58          t.tm_sec = 59;
59          t.tm_min = 55;
60          t.tm_hour = 23;
61          t.tm_mday = 31;
62          t.tm_mon = 11;
63          t.tm_year = 161;
64          t.tm_wday = 6;
65          t.tm_isdst = 0;
66          os << std::put_time(&t, "%a %b %d %H:%M:%S %Y");
67          assert(sb.str() == "Sat Dec 31 23:55:59 2061");
68      }
69      {
70          testbuf<wchar_t> sb;
71          std::wostream os(&sb);
72          os.imbue(std::locale(LOCALE_en_US_UTF_8));
73          std::tm t = {0};
74          t.tm_sec = 59;
75          t.tm_min = 55;
76          t.tm_hour = 23;
77          t.tm_mday = 31;
78          t.tm_mon = 11;
79          t.tm_year = 161;
80          t.tm_wday = 6;
81          os << std::put_time(&t, L"%a %b %d %H:%M:%S %Y");
82          assert(sb.str() == L"Sat Dec 31 23:55:59 2061");
83      }
84  }
85