genericopenlibs/cppstdlib/stl/test/eh/locale.cpp
changeset 31 ce057bb09d0b
child 34 5fae379060a7
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 #include <exception>
       
    18 #include <iostream>
       
    19 #include <locale>
       
    20 #include <ctime>
       
    21 
       
    22 using namespace std;
       
    23 
       
    24 void main()
       
    25 {
       
    26   try
       
    27   {
       
    28     locale c_loc;
       
    29     //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);
       
    30     locale sys(".ocp");
       
    31     locale::global(sys);
       
    32     cin.imbue(sys);
       
    33     cout.imbue(sys);
       
    34 
       
    35     cout<<"Locale name is: "<<sys.name().c_str()<<'\n';
       
    36 
       
    37     cout<<"Enter real number:";
       
    38     double value;
       
    39     cin>>value;
       
    40     cout<<value<<'\n';
       
    41 
       
    42         // Time test.
       
    43         long lcur_time;
       
    44         time(&lcur_time);
       
    45         struct tm* cur_time=localtime(&lcur_time);
       
    46 
       
    47         const numpunct<char>& num_punct=use_facet<numpunct<char> >(cout.getloc());
       
    48         cout << num_punct.decimal_point() << '\n';
       
    49         const time_put<char, ostreambuf_iterator<char, char_traits<char> > >& time_fac=
       
    50         use_facet<time_put<char, ostreambuf_iterator<char, char_traits<char> > > >(cout.getloc());
       
    51         time_fac.put(cout, cout, NULL, cur_time, 'x'); cout<<'\n';
       
    52         time_fac.put(cout, cout, NULL, cur_time, 'x', '#'); cout<<'\n';
       
    53         time_fac.put(cout, cout, NULL, cur_time, 'X'); cout<<'\n';
       
    54         time_fac.put(cout, cout, NULL, cur_time, 'c'); cout<<'\n';
       
    55         time_fac.put(cout, cout, NULL, cur_time, 'c', '#'); cout<<'\n';
       
    56         time_fac.put(cout, cout, NULL, cur_time, 'I'); cout<<'\n';
       
    57 
       
    58         const ctype<char>& char_type=use_facet<ctype<char> >(cout.getloc());
       
    59         if(char_type.is(ctype_base::upper, '')) puts("Upper");
       
    60         if(char_type.is(ctype_base::lower, '')) puts("Lower");
       
    61         puts("Next");
       
    62         if(isupper('', cout.getloc())) puts("Upper");
       
    63         if(islower('', cout.getloc())) puts("Lower");
       
    64         /*for(int ch=128; ch<256; ch++)
       
    65           printf("Character %c (%d) - upper %c, lower %c\n",(char)ch, ch,toupper((char)ch, cout.getloc()), tolower((char)ch, cout.getloc()));*/
       
    66   }
       
    67   catch(exception &e)
       
    68   {
       
    69     cout<<"Exception fired:\n"<<e.what()<<'\n';
       
    70   }
       
    71   catch(...)
       
    72   {
       
    73     cout<<"Unknown exception throwed!\n";
       
    74   }
       
    75   cout.flush();
       
    76 }