Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Dan Albert | b4ed5ca | 2014-08-04 18:44:48 +0000 | [diff] [blame^] | 10 | // REQUIRES: locale.en_US.UTF-8 |
| 11 | // REQUIRES: locale.fr_FR.UTF-8 |
| 12 | // REQUIRES: locale.ru_RU.UTF-8 |
| 13 | // REQUIRES: locale.zh_CN.UTF-8 |
| 14 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 15 | // <locale> |
| 16 | |
| 17 | // class time_get_byname<charT, InputIterator> |
| 18 | |
| 19 | // iter_type |
| 20 | // get_monthname(iter_type s, iter_type end, ios_base& str, |
| 21 | // ios_base::iostate& err, tm* t) const; |
| 22 | |
| 23 | #include <locale> |
| 24 | #include <cassert> |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 25 | #include "test_iterators.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 27 | #include "platform_support.h" // locale name macros |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 28 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 29 | typedef input_iterator<const wchar_t*> I; |
| 30 | |
| 31 | typedef std::time_get_byname<wchar_t, I> F; |
| 32 | |
| 33 | class my_facet |
| 34 | : public F |
| 35 | { |
| 36 | public: |
| 37 | explicit my_facet(const std::string& nm, std::size_t refs = 0) |
| 38 | : F(nm, refs) {} |
| 39 | }; |
| 40 | |
| 41 | typedef std::time_put_byname<wchar_t, wchar_t*> F2; |
| 42 | class my_facet2 |
| 43 | : public F2 |
| 44 | { |
| 45 | public: |
| 46 | explicit my_facet2(const std::string& nm, std::size_t refs = 0) |
| 47 | : F2(nm, refs) {} |
| 48 | }; |
| 49 | |
| 50 | int main() |
| 51 | { |
| 52 | std::ios ios(0); |
| 53 | std::ios_base::iostate err; |
| 54 | std::tm t; |
| 55 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 56 | const my_facet f(LOCALE_en_US_UTF_8, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 57 | const wchar_t in[] = L"June"; |
| 58 | err = std::ios_base::goodbit; |
| 59 | t = std::tm(); |
| 60 | I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); |
| 61 | assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); |
| 62 | assert(t.tm_mon == 5); |
| 63 | assert(err == std::ios_base::eofbit); |
| 64 | } |
| 65 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 66 | const my_facet f(LOCALE_fr_FR_UTF_8, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 67 | const wchar_t in[] = L"juin"; |
| 68 | err = std::ios_base::goodbit; |
| 69 | t = std::tm(); |
| 70 | I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); |
| 71 | assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); |
| 72 | assert(t.tm_mon == 5); |
| 73 | assert(err == std::ios_base::eofbit); |
| 74 | } |
| 75 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 76 | const my_facet f(LOCALE_ru_RU_UTF_8, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 77 | const wchar_t in[] = L"\x438\x44E\x43D\x44F"; |
| 78 | err = std::ios_base::goodbit; |
| 79 | t = std::tm(); |
| 80 | I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); |
| 81 | assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); |
| 82 | assert(t.tm_mon == 5); |
| 83 | assert(err == std::ios_base::eofbit); |
| 84 | } |
| 85 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 86 | const my_facet f(LOCALE_zh_CN_UTF_8, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 87 | const wchar_t in[] = L"\x516D\x6708"; |
| 88 | err = std::ios_base::goodbit; |
| 89 | t = std::tm(); |
| 90 | I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); |
| 91 | assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); |
| 92 | assert(t.tm_mon == 5); |
| 93 | assert(err == std::ios_base::eofbit); |
| 94 | } |
| 95 | } |