| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // NetBSD does not support LC_TIME at the moment |
| 10 | // XFAIL: netbsd |
| 11 | |
| 12 | // XFAIL: LIBCXX-FREEBSD-FIXME |
| 13 | |
| 14 | // REQUIRES: locale.en_US.UTF-8 |
| 15 | // REQUIRES: locale.fr_FR.UTF-8 |
| 16 | // REQUIRES: locale.ja_JP.UTF-8 |
| 17 | |
| 18 | // <locale> |
| 19 | |
| 20 | // template <class CharT, class OutputIterator = ostreambuf_iterator<CharT> > |
| 21 | // class time_put_byname |
| 22 | // : public time_put<CharT, OutputIterator> |
| 23 | // { |
| 24 | // public: |
| 25 | // explicit time_put_byname(const char* nm, size_t refs = 0); |
| 26 | // explicit time_put_byname(const string& nm, size_t refs = 0); |
| 27 | // |
| 28 | // protected: |
| 29 | // ~time_put_byname(); |
| 30 | // }; |
| 31 | |
| 32 | #include <locale> |
| 33 | #include <cassert> |
| 34 | #include "test_macros.h" |
| 35 | #include "test_iterators.h" |
| 36 | |
| 37 | #include "platform_support.h" // locale name macros |
| 38 | |
| 39 | typedef std::time_put_byname<char, cpp17_output_iterator<char*> > F; |
| 40 | |
| 41 | class my_facet |
| 42 | : public F |
| 43 | { |
| 44 | public: |
| 45 | explicit my_facet(const std::string& nm, std::size_t refs = 0) |
| 46 | : F(nm, refs) {} |
| 47 | }; |
| 48 | |
| 49 | int main(int, char**) |
| 50 | { |
| 51 | char str[200]; |
| 52 | tm t; |
| 53 | t.tm_sec = 6; |
| 54 | t.tm_min = 3; |
| 55 | t.tm_hour = 13; |
| 56 | t.tm_mday = 2; |
| 57 | t.tm_mon = 4; |
| 58 | t.tm_year = 109; |
| 59 | t.tm_wday = 6; |
| 60 | t.tm_yday = -1; |
| 61 | t.tm_isdst = 1; |
| 62 | std::ios ios(0); |
| 63 | { |
| 64 | const my_facet f(LOCALE_en_US_UTF_8, 1); |
| 65 | std::string pat("Today is %A which is abbreviated %a." ); |
| 66 | cpp17_output_iterator<char*> iter = |
| 67 | f.put(cpp17_output_iterator<char*>(str), ios, '*', &t, pat.data(), pat.data() + pat.size()); |
| 68 | std::string ex(str, base(iter)); |
| 69 | assert(ex == "Today is Saturday which is abbreviated Sat." ); |
| 70 | } |
| 71 | { |
| 72 | const my_facet f(LOCALE_fr_FR_UTF_8, 1); |
| 73 | std::string pat("Today is %A which is abbreviated '%a'." ); |
| 74 | cpp17_output_iterator<char*> iter = |
| 75 | f.put(cpp17_output_iterator<char*>(str), ios, '*', &t, pat.data(), pat.data() + pat.size()); |
| 76 | std::string ex(str, base(iter)); |
| 77 | assert((ex == "Today is Samedi which is abbreviated 'Sam'." )|| |
| 78 | (ex == "Today is samedi which is abbreviated 'sam'." )|| |
| 79 | (ex == "Today is samedi which is abbreviated 'sam.'." )); |
| 80 | } |
| 81 | { |
| 82 | const my_facet f(LOCALE_ja_JP_UTF_8, 1); |
| 83 | std::string pat("Today is %A which is the %uth day or alternatively %Ou." ); |
| 84 | cpp17_output_iterator<char*> iter = |
| 85 | f.put(cpp17_output_iterator<char*>(str), ios, '*', &t, pat.data(), pat.data() + pat.size()); |
| 86 | std::string ex(str, base(iter)); |
| 87 | #if defined(_WIN32) || defined(__APPLE__) || defined(_AIX) |
| 88 | // These platforms have no alternative |
| 89 | assert(ex == "Today is \xE5\x9C\x9F\xE6\x9B\x9C\xE6\x97\xA5 which is the 6th day or alternatively 6." ); |
| 90 | #else |
| 91 | assert(ex == "Today is \xE5\x9C\x9F\xE6\x9B\x9C\xE6\x97\xA5 which is the 6th day or alternatively \xE5\x85\xAD." ); |
| 92 | #endif |
| 93 | } |
| 94 | return 0; |
| 95 | } |
| 96 | |