put1.pass.cpp revision e2f2a15066552758a508e8a7325e0ccad4a5389b
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// template <class CharT, class OutputIterator = ostreambuf_iterator<CharT> >
13// class time_put_byname
14//     : public time_put<CharT, OutputIterator>
15// {
16// public:
17//     explicit time_put_byname(const char* nm, size_t refs = 0);
18//     explicit time_put_byname(const string& nm, size_t refs = 0);
19//
20// protected:
21//     ~time_put_byname();
22// };
23
24#include <locale>
25#include <cassert>
26#include "iterators.h"
27
28typedef std::time_put_byname<char, output_iterator<char*> > F;
29
30class my_facet
31    : public F
32{
33public:
34    explicit my_facet(const std::string& nm, std::size_t refs = 0)
35        : F(nm, refs) {}
36};
37
38int main()
39{
40    char str[200];
41    output_iterator<char*> iter;
42    tm t;
43    t.tm_sec = 6;
44    t.tm_min = 3;
45    t.tm_hour = 13;
46    t.tm_mday = 2;
47    t.tm_mon = 4;
48    t.tm_year = 109;
49    t.tm_wday = 6;
50    t.tm_yday = -1;
51    t.tm_isdst = 1;
52    std::ios ios(0);
53    {
54        const my_facet f("en_US.UTF-8", 1);
55        std::string pat("Today is %A which is abreviated %a.");
56        iter = f.put(output_iterator<char*>(str), ios, '*', &t,
57                     pat.data(), pat.data() + pat.size());
58        std::string ex(str, iter.base());
59        assert(ex == "Today is Saturday which is abreviated Sat.");
60    }
61    {
62        const my_facet f("fr_FR.UTF-8", 1);
63        std::string pat("Today is %A which is abreviated %a.");
64        iter = f.put(output_iterator<char*>(str), ios, '*', &t,
65                     pat.data(), pat.data() + pat.size());
66        std::string ex(str, iter.base());
67        assert((ex == "Today is Samedi which is abreviated Sam.")||
68               (ex == "Today is samedi which is abreviated sam." ));
69    }
70}
71