16fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs//===----------------------------------------------------------------------===// 26fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs// 36fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs// The LLVM Compiler Infrastructure 46fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs// 56fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs// This file is dual licensed under the MIT and the University of Illinois Open 66fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs// Source Licenses. See LICENSE.TXT for details. 76fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs// 86fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs//===----------------------------------------------------------------------===// 96fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs 106fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs// <locale> 116fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs 126fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs// template <class charT> class ctype_byname; 136fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs 146fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs// bool is(mask m, charT c) const; 156fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs 166fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs#include <locale> 176fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs#include <type_traits> 186fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs#include <cassert> 196fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs 206fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofsint main() 216fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs{ 226fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs { 236fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs std::locale l("C"); 246fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs { 256fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs typedef std::ctype<wchar_t> WF; 266fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs const WF& wf = std::use_facet<WF>(l); 276fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs typedef std::ctype<char> CF; 286fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs const CF& cf = std::use_facet<CF>(l); 296fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs 306fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs // The ctype masks in Newlib don't form a proper bitmask because 316fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs // the mask is only 8 bits wide, and there are more than 8 mask 326fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs // kinds. This means that the mask for alpha is (_U | _L), which 336fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs // is tricky to match in the do_is implementation because in 346fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs // [22.4.1.1.2 2] the standard specifies that the match code behaves 356fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs // like (m & M) != 0, but following this exactly would give false 366fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs // positives for characters that are both 'upper' and 'alpha', but 376fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs // not 'lower', for example. 386fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs assert( wf.is(WF::upper, L'A')); 396fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs assert( cf.is(CF::upper, 'A')); 406fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs assert(!wf.is(WF::lower, L'A')); 416fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs assert(!cf.is(CF::lower, 'A')); 426fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs assert( wf.is(WF::alpha, L'A')); 436fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs assert( cf.is(CF::alpha, 'A')); 446fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs 456fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs assert(!wf.is(WF::upper, L'a')); 466fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs assert(!cf.is(CF::upper, 'a')); 476fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs assert( wf.is(WF::lower, L'a')); 486fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs assert( cf.is(CF::lower, 'a')); 496fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs assert( wf.is(WF::alpha, L'a')); 506fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs assert( cf.is(CF::alpha, 'a')); 516fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs } 526fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs } 536fb33ea8fb10be941c1b66d7054a67a9356a893dJonathan Roelofs} 54