1 // locale_info.cpp ---------------------------------------------------------//
2
3 // Copyright Beman Dawes 2011
4
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
7
8 #include <locale>
9 #include <iostream>
10 #include <exception>
11 #include <cstdlib>
12 using namespace std;
13
14 #ifdef _MSC_VER
15 # pragma warning(push)
16 # pragma warning(disable: 4996) // ... Function call with parameters that may be unsafe
17 #endif
18
19 namespace
20 {
facet_info(const locale & loc,const char * msg)21 void facet_info(const locale& loc, const char* msg)
22 {
23 cout << "has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >("
24 << msg << ") is "
25 << (has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc)
26 ? "true\n"
27 : "false\n");
28 }
29
default_info()30 void default_info()
31 {
32 try
33 {
34 locale loc;
35 cout << "\nlocale default construction OK" << endl;
36 facet_info(loc, "locale()");
37 }
38 catch (const exception& ex)
39 {
40 cout << "\nlocale default construction threw: " << ex.what() << endl;
41 }
42 }
43
null_string_info()44 void null_string_info()
45 {
46 try
47 {
48 locale loc("");
49 cout << "\nlocale(\"\") construction OK" << endl;
50 facet_info(loc, "locale(\"\")");
51 }
52 catch (const exception& ex)
53 {
54 cout << "\nlocale(\"\") construction threw: " << ex.what() << endl;
55 }
56 }
57
classic_info()58 void classic_info()
59 {
60 try
61 {
62 locale loc(locale::classic());
63 cout << "\nlocale(locale::classic()) copy construction OK" << endl;
64 facet_info(loc, "locale::classic()");
65 }
66 catch (const exception& ex)
67 {
68 cout << "\nlocale(locale::clasic()) copy construction threw: " << ex.what() << endl;
69 }
70 }
71 }
72
main()73 int main()
74 {
75 const char* lang = getenv("LANG");
76 cout << "\nLANG environmental variable is "
77 << (lang ? lang : "not present") << endl;
78
79 default_info();
80 null_string_info();
81 classic_info();
82
83 return 0;
84 }
85
86 #ifdef _MSC_VER
87 # pragma warning(pop)
88 #endif
89