summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/localization/locale.categories/category.ctype/locale.ctype.byname/mask.pass.cpp
blob: a09072a987884db6627f70a38b01ef3ad1d9b311 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// <locale>

// template <class charT> class ctype_byname;

// bool is(mask m, charT c) const;

#include <locale>
#include <type_traits>
#include <cassert>

int main()
{
    {
        std::locale l("C");
        {
            typedef std::ctype<wchar_t> WF;
            const WF& wf = std::use_facet<WF>(l);
            typedef std::ctype<char> CF;
            const CF& cf = std::use_facet<CF>(l);

            // The ctype masks in Newlib don't form a proper bitmask because
            // the mask is only 8 bits wide, and there are more than 8 mask
            // kinds. This means that the mask for alpha is (_U | _L), which
            // is tricky to match in the do_is implementation because in
            // [22.4.1.1.2 2] the standard specifies that the match code behaves
            // like (m & M) != 0, but following this exactly would give false
            // positives for characters that are both 'upper' and 'alpha', but
            // not 'lower', for example.
            assert( wf.is(WF::upper, L'A'));
            assert( cf.is(CF::upper,  'A'));
            assert(!wf.is(WF::lower, L'A'));
            assert(!cf.is(CF::lower,  'A'));
            assert( wf.is(WF::alpha, L'A'));
            assert( cf.is(CF::alpha,  'A'));

            assert(!wf.is(WF::upper, L'a'));
            assert(!cf.is(CF::upper,  'a'));
            assert( wf.is(WF::lower, L'a'));
            assert( cf.is(CF::lower,  'a'));
            assert( wf.is(WF::alpha, L'a'));
            assert( cf.is(CF::alpha,  'a'));
        }
    }
}
OpenPOWER on IntegriCloud