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 | // template <class charT> class collate_byname |
| 13 | |
| 14 | // string_type transform(const charT* low, const charT* high) const; |
| 15 | |
Dan Albert | 5980ce3 | 2014-11-21 01:23:04 +0000 | [diff] [blame] | 16 | // REQUIRES: locale.en_US.UTF-8 |
| 17 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 18 | #include <locale> |
| 19 | #include <string> |
| 20 | #include <cassert> |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 24 | #include "platform_support.h" // locale name macros |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 25 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | int main() |
| 27 | { |
David Chisnall | e2f2a15 | 2011-09-21 08:19:20 +0000 | [diff] [blame] | 28 | // Ensure that the default locale is not C. If it is, the second tests will fail. |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 29 | putenv(const_cast<char*>("LANG=" LOCALE_en_US_UTF_8)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 30 | { |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 31 | std::locale l(LOCALE_en_US_UTF_8); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 32 | { |
| 33 | std::string x("1234"); |
| 34 | const std::collate<char>& f = std::use_facet<std::collate<char> >(l); |
| 35 | assert(f.transform(x.data(), x.data() + x.size()) != x); |
| 36 | } |
| 37 | { |
| 38 | std::wstring x(L"1234"); |
| 39 | const std::collate<wchar_t>& f = std::use_facet<std::collate<wchar_t> >(l); |
| 40 | assert(f.transform(x.data(), x.data() + x.size()) != x); |
| 41 | } |
| 42 | } |
| 43 | { |
| 44 | std::locale l(""); |
| 45 | { |
| 46 | std::string x("1234"); |
| 47 | const std::collate<char>& f = std::use_facet<std::collate<char> >(l); |
| 48 | assert(f.transform(x.data(), x.data() + x.size()) != x); |
| 49 | } |
| 50 | { |
| 51 | std::wstring x(L"1234"); |
| 52 | const std::collate<wchar_t>& f = std::use_facet<std::collate<wchar_t> >(l); |
| 53 | assert(f.transform(x.data(), x.data() + x.size()) != x); |
| 54 | } |
| 55 | } |
| 56 | { |
| 57 | std::locale l("C"); |
| 58 | { |
| 59 | std::string x("1234"); |
| 60 | const std::collate<char>& f = std::use_facet<std::collate<char> >(l); |
| 61 | assert(f.transform(x.data(), x.data() + x.size()) == x); |
| 62 | } |
| 63 | { |
| 64 | std::wstring x(L"1234"); |
| 65 | const std::collate<wchar_t>& f = std::use_facet<std::collate<wchar_t> >(l); |
| 66 | assert(f.transform(x.data(), x.data() + x.size()) == x); |
| 67 | } |
| 68 | } |
| 69 | } |