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 |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 12 | // REQUIRES: locale.ru_RU.UTF-8 |
Dan Albert | b4ed5ca | 2014-08-04 18:44:48 +0000 | [diff] [blame] | 13 | // REQUIRES: locale.zh_CN.UTF-8 |
| 14 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 15 | // NOTE: debian and opensuse use old locale data for ru_RU.UTF-8 abreviated |
| 16 | // months. This locale data was changed in glibc 2.14. |
| 17 | // Debian uses glibc 2.13 as of 20/11/2014 |
| 18 | // OpenSuse uses glibc 2.19 with old locale data as of 20/11/2014 |
| 19 | // XFAIL: debian, opensuse |
| 20 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | // <locale> |
| 22 | |
| 23 | // class time_get_byname<charT, InputIterator> |
| 24 | |
| 25 | // iter_type |
| 26 | // get_monthname(iter_type s, iter_type end, ios_base& str, |
| 27 | // ios_base::iostate& err, tm* t) const; |
| 28 | |
| 29 | #include <locale> |
| 30 | #include <cassert> |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 31 | #include "test_iterators.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 32 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 33 | #include "platform_support.h" // locale name macros |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 34 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | typedef input_iterator<const char*> I; |
| 36 | |
| 37 | typedef std::time_get_byname<char, I> F; |
| 38 | |
| 39 | class my_facet |
| 40 | : public F |
| 41 | { |
| 42 | public: |
| 43 | explicit my_facet(const std::string& nm, std::size_t refs = 0) |
| 44 | : F(nm, refs) {} |
| 45 | }; |
| 46 | |
| 47 | int main() |
| 48 | { |
| 49 | std::ios ios(0); |
| 50 | std::ios_base::iostate err; |
| 51 | std::tm t; |
| 52 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 53 | const my_facet f(LOCALE_en_US_UTF_8, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 54 | const char in[] = "June"; |
| 55 | err = std::ios_base::goodbit; |
| 56 | t = std::tm(); |
| 57 | I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); |
| 58 | assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); |
| 59 | assert(t.tm_mon == 5); |
| 60 | assert(err == std::ios_base::eofbit); |
| 61 | } |
| 62 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 63 | const my_facet f(LOCALE_fr_FR_UTF_8, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 64 | const char in[] = "juin"; |
| 65 | err = std::ios_base::goodbit; |
| 66 | t = std::tm(); |
| 67 | I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); |
| 68 | assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); |
| 69 | assert(t.tm_mon == 5); |
| 70 | assert(err == std::ios_base::eofbit); |
| 71 | } |
| 72 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 73 | const my_facet f(LOCALE_ru_RU_UTF_8, 1); |
| 74 | const char in[] = "\xD0\xB8\xD1\x8E\xD0\xBD\xD1\x8F"; |
| 75 | err = std::ios_base::goodbit; |
| 76 | t = std::tm(); |
| 77 | I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); |
| 78 | assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); |
| 79 | assert(t.tm_mon == 5); |
| 80 | assert(err == std::ios_base::eofbit); |
| 81 | } |
| 82 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 83 | const my_facet f(LOCALE_zh_CN_UTF_8, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | const char in[] = "\xE5\x85\xAD\xE6\x9C\x88"; |
| 85 | err = std::ios_base::goodbit; |
| 86 | t = std::tm(); |
| 87 | I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); |
| 88 | assert(i.base() == in+sizeof(in)/sizeof(in[0])-1); |
| 89 | assert(t.tm_mon == 5); |
| 90 | assert(err == std::ios_base::eofbit); |
| 91 | } |
| 92 | } |