xref: /reactos/sdk/lib/3rdparty/stlport/test/eh/locale.cpp (revision c2c66aff)
1 #include <exception>
2 #include <iostream>
3 #include <locale>
4 #include <ctime>
5 
6 using namespace std;
7 
main()8 void main()
9 {
10   try
11   {
12     locale c_loc;
13     //locale sys(c_loc, "LC_TIME=UKR_UKR.OCP;LC_NUMERIC=RUS_RUS.OCP;LC_CTYPE=ukr_ukr.ocp;", locale::numeric | locale::time | locale::ctype);
14     locale sys(".ocp");
15     locale::global(sys);
16     cin.imbue(sys);
17     cout.imbue(sys);
18 
19     cout<<"Locale name is: "<<sys.name().c_str()<<'\n';
20 
21     cout<<"Enter real number:";
22     double value;
23     cin>>value;
24     cout<<value<<'\n';
25 
26         // Time test.
27         long lcur_time;
28         time(&lcur_time);
29         struct tm* cur_time=localtime(&lcur_time);
30 
31         const numpunct<char>& num_punct=use_facet<numpunct<char> >(cout.getloc());
32         cout << num_punct.decimal_point() << '\n';
33         const time_put<char, ostreambuf_iterator<char, char_traits<char> > >& time_fac=
34         use_facet<time_put<char, ostreambuf_iterator<char, char_traits<char> > > >(cout.getloc());
35         time_fac.put(cout, cout, NULL, cur_time, 'x'); cout<<'\n';
36         time_fac.put(cout, cout, NULL, cur_time, 'x', '#'); cout<<'\n';
37         time_fac.put(cout, cout, NULL, cur_time, 'X'); cout<<'\n';
38         time_fac.put(cout, cout, NULL, cur_time, 'c'); cout<<'\n';
39         time_fac.put(cout, cout, NULL, cur_time, 'c', '#'); cout<<'\n';
40         time_fac.put(cout, cout, NULL, cur_time, 'I'); cout<<'\n';
41 
42         const ctype<char>& char_type=use_facet<ctype<char> >(cout.getloc());
43         if(char_type.is(ctype_base::upper, '�')) puts("Upper");
44         if(char_type.is(ctype_base::lower, '�')) puts("Lower");
45         puts("Next");
46         if(isupper('�', cout.getloc())) puts("Upper");
47         if(islower('�', cout.getloc())) puts("Lower");
48         /*for(int ch=128; ch<256; ch++)
49           printf("Character %c (%d) - upper %c, lower %c\n",(char)ch, ch,toupper((char)ch, cout.getloc()), tolower((char)ch, cout.getloc()));*/
50   }
51   catch(exception &e)
52   {
53     cout<<"Exception fired:\n"<<e.what()<<'\n';
54   }
55   catch(...)
56   {
57     cout<<"Unknown exception throwed!\n";
58   }
59   cout.flush();
60 }
61