Home | History | Annotate | Download | only in locale.time.put.byname
      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 "test_iterators.h"
     27 
     28 #include "platform_support.h" // locale name macros
     29 
     30 typedef std::time_put_byname<char, output_iterator<char*> > 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 int main()
     41 {
     42     char str[200];
     43     output_iterator<char*> iter;
     44     tm t;
     45     t.tm_sec = 6;
     46     t.tm_min = 3;
     47     t.tm_hour = 13;
     48     t.tm_mday = 2;
     49     t.tm_mon = 4;
     50     t.tm_year = 109;
     51     t.tm_wday = 6;
     52     t.tm_yday = -1;
     53     t.tm_isdst = 1;
     54     std::ios ios(0);
     55     {
     56         const my_facet f(LOCALE_en_US_UTF_8, 1);
     57         std::string pat("Today is %A which is abreviated %a.");
     58         iter = f.put(output_iterator<char*>(str), ios, '*', &t,
     59                      pat.data(), pat.data() + pat.size());
     60         std::string ex(str, iter.base());
     61         assert(ex == "Today is Saturday which is abreviated Sat.");
     62     }
     63     {
     64         const my_facet f(LOCALE_fr_FR_UTF_8, 1);
     65         std::string pat("Today is %A which is abreviated %a.");
     66         iter = f.put(output_iterator<char*>(str), ios, '*', &t,
     67                      pat.data(), pat.data() + pat.size());
     68         std::string ex(str, iter.base());
     69         assert((ex == "Today is Samedi which is abreviated Sam.")||
     70                (ex == "Today is samedi which is abreviated sam." ));
     71     }
     72 }
     73