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 | |
| 10 | // <locale> |
| 11 | |
| 12 | // class time_get_byname<charT, InputIterator> |
| 13 | |
| 14 | // iter_type |
| 15 | // get_monthname(iter_type s, iter_type end, ios_base& str, |
| 16 | // ios_base::iostate& err, tm* t) const; |
| 17 | |
| 18 | #include <locale> |
| 19 | #include <cassert> |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 20 | #include "test_iterators.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 22 | #include "platform_support.h" // locale name macros |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 23 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | typedef input_iterator<const wchar_t*> I; |
| 25 | |
| 26 | typedef std::time_get_byname<wchar_t, I> F; |
| 27 | |
| 28 | class my_facet |
| 29 | : public F |
| 30 | { |
| 31 | public: |
| 32 | explicit my_facet(const std::string& nm, std::size_t refs = 0) |
| 33 | : F(nm, refs) {} |
| 34 | }; |
| 35 | |
| 36 | typedef std::time_put_byname<wchar_t, wchar_t*> F2; |
| 37 | class my_facet2 |
| 38 | : public F2 |
| 39 | { |
| 40 | public: |
| 41 | explicit my_facet2(const std::string& nm, std::size_t refs = 0) |
| 42 | : F2(nm, refs) {} |
| 43 | }; |
| 44 | |
| 45 | int main() |
| 46 | { |
| 47 | std::ios ios(0); |
| 48 | std::ios_base::iostate err; |
| 49 | std::tm t; |
| 50 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 51 | const my_facet f(LOCALE_en_US_UTF_8, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 52 | const wchar_t in[] = L"June"; |
| 53 | err = std::ios_base::goodbit; |
| 54 | t = std::tm(); |
| 55 | I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); |
| 56 | assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); |
| 57 | assert(t.tm_mon == 5); |
| 58 | assert(err == std::ios_base::eofbit); |
| 59 | } |
| 60 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 61 | const my_facet f(LOCALE_fr_FR_UTF_8, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | const wchar_t in[] = L"juin"; |
| 63 | err = std::ios_base::goodbit; |
| 64 | t = std::tm(); |
| 65 | I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); |
| 66 | assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); |
| 67 | assert(t.tm_mon == 5); |
| 68 | assert(err == std::ios_base::eofbit); |
| 69 | } |
| 70 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 71 | const my_facet f(LOCALE_ru_RU_UTF_8, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 72 | const wchar_t in[] = L"\x438\x44E\x43D\x44F"; |
| 73 | err = std::ios_base::goodbit; |
| 74 | t = std::tm(); |
| 75 | I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); |
| 76 | assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); |
| 77 | assert(t.tm_mon == 5); |
| 78 | assert(err == std::ios_base::eofbit); |
| 79 | } |
| 80 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 81 | const my_facet f(LOCALE_zh_CN_UTF_8, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | const wchar_t in[] = L"\x516D\x6708"; |
| 83 | err = std::ios_base::goodbit; |
| 84 | t = std::tm(); |
| 85 | I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); |
| 86 | assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); |
| 87 | assert(t.tm_mon == 5); |
| 88 | assert(err == std::ios_base::eofbit); |
| 89 | } |
| 90 | } |