Home | History | Annotate | Download | only in locale.ctype.byname
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <locale>
     11 
     12 // template <class charT> class ctype_byname;
     13 
     14 // bool is(mask m, charT c) const;
     15 
     16 #include <locale>
     17 #include <type_traits>
     18 #include <cassert>
     19 
     20 int main()
     21 {
     22     {
     23         std::locale l("C");
     24         {
     25             typedef std::ctype<wchar_t> WF;
     26             const WF& wf = std::use_facet<WF>(l);
     27             typedef std::ctype<char> CF;
     28             const CF& cf = std::use_facet<CF>(l);
     29 
     30             // The ctype masks in Newlib don't form a proper bitmask because
     31             // the mask is only 8 bits wide, and there are more than 8 mask
     32             // kinds. This means that the mask for alpha is (_U | _L), which
     33             // is tricky to match in the do_is implementation because in
     34             // [22.4.1.1.2 2] the standard specifies that the match code behaves
     35             // like (m & M) != 0, but following this exactly would give false
     36             // positives for characters that are both 'upper' and 'alpha', but
     37             // not 'lower', for example.
     38             assert( wf.is(WF::upper, L'A'));
     39             assert( cf.is(CF::upper,  'A'));
     40             assert(!wf.is(WF::lower, L'A'));
     41             assert(!cf.is(CF::lower,  'A'));
     42             assert( wf.is(WF::alpha, L'A'));
     43             assert( cf.is(CF::alpha,  'A'));
     44 
     45             assert(!wf.is(WF::upper, L'a'));
     46             assert(!cf.is(CF::upper,  'a'));
     47             assert( wf.is(WF::lower, L'a'));
     48             assert( cf.is(CF::lower,  'a'));
     49             assert( wf.is(WF::alpha, L'a'));
     50             assert( cf.is(CF::alpha,  'a'));
     51         }
     52     }
     53 }
     54