123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849 |
- ///////////////////////////////////////////////////////////////////////////////
- // c_ctype.hpp
- //
- // Copyright 2008 Eric Niebler. Distributed under the Boost
- // Software License, Version 1.0. (See accompanying file
- // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- #ifndef BOOST_XPRESSIVE_TRAITS_DETAIL_C_CTYPE_HPP_EAN_10_04_2005
- #define BOOST_XPRESSIVE_TRAITS_DETAIL_C_CTYPE_HPP_EAN_10_04_2005
- // MS compatible compilers support #pragma once
- #if defined(_MSC_VER)
- # pragma once
- #endif
- #include <cctype>
- #include <cstring>
- #include <boost/mpl/assert.hpp>
- #include <boost/xpressive/detail/detail_fwd.hpp>
- #ifndef BOOST_XPRESSIVE_NO_WREGEX
- # include <cwchar>
- # include <cwctype>
- #endif
- namespace boost { namespace xpressive { namespace detail
- {
- ///////////////////////////////////////////////////////////////////////////////
- // isnewline
- //
- inline bool isnewline(char ch)
- {
- switch(ch)
- {
- case L'\n': case L'\r': case L'\f':
- return true;
- default:
- return false;
- }
- }
- ///////////////////////////////////////////////////////////////////////////////
- // iswnewline
- //
- inline bool iswnewline(wchar_t ch)
- {
- switch(ch)
- {
- case L'\n': case L'\r': case L'\f': case 0x2028u: case 0x2029u: case 0x85u:
- return true;
- default:
- return false;
- }
- }
- ///////////////////////////////////////////////////////////////////////////////
- // classname_a
- //
- template<typename FwdIter>
- inline std::string classname_a(FwdIter begin, FwdIter end)
- {
- std::string name(begin, end);
- for(std::size_t i = 0; i < name.size(); ++i)
- {
- using namespace std;
- name[i] = static_cast<char>(tolower(static_cast<unsigned char>(name[i])));
- }
- return name;
- }
- #ifndef BOOST_XPRESSIVE_NO_WREGEX
- ///////////////////////////////////////////////////////////////////////////////
- // classname_w
- //
- template<typename FwdIter>
- inline std::wstring classname_w(FwdIter begin, FwdIter end)
- {
- std::wstring name(begin, end);
- for(std::size_t i = 0; i < name.size(); ++i)
- {
- using namespace std;
- name[i] = towlower(name[i]);
- }
- return name;
- }
- #endif
- ///////////////////////////////////////////////////////////////////////////////
- // char_class_impl
- //
- template<typename Char>
- struct char_class_impl;
- #if defined(__QNXNTO__)
- ///////////////////////////////////////////////////////////////////////////////
- //
- template<>
- struct char_class_impl<char>
- {
- typedef short char_class_type;
- BOOST_MPL_ASSERT_RELATION(0x07FF, ==, (_XB|_XA|_XS|_BB|_CN|_DI|_LO|_PU|_SP|_UP|_XD));
- BOOST_STATIC_CONSTANT(short, char_class_underscore = 0x1000);
- BOOST_STATIC_CONSTANT(short, char_class_newline = 0x2000);
- template<typename FwdIter>
- static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
- {
- using namespace std;
- string const name = classname_a(begin, end);
- if(name == "alnum") return _DI|_LO|_UP|_XA;
- if(name == "alpha") return _LO|_UP|_XA;
- if(name == "blank") return _SP|_XB;
- if(name == "cntrl") return _BB;
- if(name == "d") return _DI;
- if(name == "digit") return _DI;
- if(name == "graph") return _DI|_LO|_PU|_UP|_XA;
- if(name == "lower") return icase ? (_LO|_UP) : _LO;
- if(name == "newline") return char_class_newline;
- if(name == "print") return _DI|_LO|_PU|_SP|_UP|_XA;
- if(name == "punct") return _PU;
- if(name == "s") return _CN|_SP|_XS;
- if(name == "space") return _CN|_SP|_XS;
- if(name == "upper") return icase ? (_UP|_LO) : _UP;
- if(name == "w") return _DI|_LO|_UP|_XA|char_class_underscore;
- if(name == "xdigit") return _XD;
- return 0;
- }
- static bool isctype(char ch, char_class_type mask)
- {
- using namespace std;
- if(0 != (_Getchrtype((unsigned char)ch) & mask))
- {
- return true;
- }
- switch(ch)
- {
- case '_': return 0 != (mask & char_class_underscore);
- case '\n': case '\r': case '\f': return 0 != (mask & char_class_newline);
- default:;
- }
- return false;
- }
- };
- #ifndef BOOST_XPRESSIVE_NO_WREGEX
- ///////////////////////////////////////////////////////////////////////////////
- //
- template<>
- struct char_class_impl<wchar_t>
- {
- typedef int char_class_type;
- //BOOST_STATIC_CONSTANT(int, char_class_alnum = 0x0001);
- BOOST_STATIC_CONSTANT(int, char_class_alpha = 0x0002);
- BOOST_STATIC_CONSTANT(int, char_class_blank = 0x0004);
- BOOST_STATIC_CONSTANT(int, char_class_cntrl = 0x0008);
- BOOST_STATIC_CONSTANT(int, char_class_digit = 0x0010);
- //BOOST_STATIC_CONSTANT(int, char_class_graph = 0x0020);
- BOOST_STATIC_CONSTANT(int, char_class_lower = 0x0040);
- //BOOST_STATIC_CONSTANT(int, char_class_print = 0x0080);
- BOOST_STATIC_CONSTANT(int, char_class_punct = 0x0100);
- BOOST_STATIC_CONSTANT(int, char_class_space = 0x0200);
- BOOST_STATIC_CONSTANT(int, char_class_upper = 0x0400);
- BOOST_STATIC_CONSTANT(int, char_class_underscore = 0x0800);
- BOOST_STATIC_CONSTANT(int, char_class_xdigit = 0x1000);
- BOOST_STATIC_CONSTANT(int, char_class_newline = 0x2000);
- template<typename FwdIter>
- static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
- {
- using namespace std;
- wstring const name = classname_w(begin, end);
- if(name == L"alnum") return char_class_alpha|char_class_digit;
- if(name == L"alpha") return char_class_alpha;
- if(name == L"blank") return char_class_blank;
- if(name == L"cntrl") return char_class_cntrl;
- if(name == L"d") return char_class_digit;
- if(name == L"digit") return char_class_digit;
- if(name == L"graph") return char_class_punct|char_class_alpha|char_class_digit;
- if(name == L"lower") return icase ? (char_class_lower|char_class_upper) : char_class_lower;
- if(name == L"newline") return char_class_newline;
- if(name == L"print") return char_class_blank|char_class_punct|char_class_alpha|char_class_digit;
- if(name == L"punct") return char_class_punct;
- if(name == L"s") return char_class_space;
- if(name == L"space") return char_class_space;
- if(name == L"upper") return icase ? (char_class_upper|char_class_lower) : char_class_upper;
- if(name == L"w") return char_class_alpha|char_class_digit|char_class_underscore;
- if(name == L"xdigit") return char_class_xdigit;
- return 0;
- }
- static bool isctype(wchar_t ch, char_class_type mask)
- {
- using namespace std;
- return ((char_class_alpha & mask) && iswalpha(ch))
- || ((char_class_blank & mask) && (L' ' == ch || L'\t' == ch)) // BUGBUG
- || ((char_class_cntrl & mask) && iswcntrl(ch))
- || ((char_class_digit & mask) && iswdigit(ch))
- || ((char_class_lower & mask) && iswlower(ch))
- || ((char_class_newline & mask) && detail::iswnewline(ch))
- || ((char_class_punct & mask) && iswpunct(ch))
- || ((char_class_space & mask) && iswspace(ch))
- || ((char_class_upper & mask) && iswupper(ch))
- || ((char_class_underscore & mask) && L'_' == ch)
- || ((char_class_xdigit & mask) && iswxdigit(ch))
- ;
- }
- };
- #endif
- #elif defined(__MINGW32_VERSION)
- ///////////////////////////////////////////////////////////////////////////////
- //
- template<>
- struct char_class_impl<char>
- {
- typedef int char_class_type;
- BOOST_MPL_ASSERT_RELATION(0x81FF, ==, (_ALPHA|_UPPER|_LOWER|_DIGIT|_SPACE|_PUNCT|_CONTROL|_BLANK|_HEX|_LEADBYTE));
- BOOST_STATIC_CONSTANT(int, char_class_underscore = 0x1000);
- BOOST_STATIC_CONSTANT(int, char_class_newline = 0x2000);
- template<typename FwdIter>
- static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
- {
- using namespace std;
- string const name = classname_a(begin, end);
- if(name == "alnum") return _ALPHA|_DIGIT;
- if(name == "alpha") return _ALPHA;
- if(name == "blank") return _BLANK; // this is ONLY space!!!
- if(name == "cntrl") return _CONTROL;
- if(name == "d") return _DIGIT;
- if(name == "digit") return _DIGIT;
- if(name == "graph") return _PUNCT|_ALPHA|_DIGIT;
- if(name == "lower") return icase ? (_LOWER|_UPPER) : _LOWER;
- if(name == "newline") return char_class_newline;
- if(name == "print") return _BLANK|_PUNCT|_ALPHA|_DIGIT;
- if(name == "punct") return _PUNCT;
- if(name == "s") return _SPACE;
- if(name == "space") return _SPACE;
- if(name == "upper") return icase ? (_UPPER|_LOWER) : _UPPER;
- if(name == "w") return _ALPHA|_DIGIT|char_class_underscore;
- if(name == "xdigit") return _HEX;
- return 0;
- }
- static bool isctype(char ch, char_class_type mask)
- {
- using namespace std;
- if(0 != _isctype(static_cast<unsigned char>(ch), mask))
- {
- return true;
- }
- switch(ch)
- {
- case '\t': return 0 != (mask & _BLANK);
- case '_': return 0 != (mask & char_class_underscore);
- case '\n': case '\r': case '\f': return 0 != (mask & char_class_newline);
- default:;
- }
- return false;
- }
- };
- #ifndef BOOST_XPRESSIVE_NO_WREGEX
- ///////////////////////////////////////////////////////////////////////////////
- //
- template<>
- struct char_class_impl<wchar_t>
- {
- typedef wctype_t char_class_type;
- BOOST_MPL_ASSERT_RELATION(0x81FF, ==, (_ALPHA|_UPPER|_LOWER|_DIGIT|_SPACE|_PUNCT|_CONTROL|_BLANK|_HEX|_LEADBYTE));
- BOOST_STATIC_CONSTANT(int, char_class_underscore = 0x1000);
- BOOST_STATIC_CONSTANT(int, char_class_newline = 0x2000);
- template<typename FwdIter>
- static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
- {
- using namespace std;
- wstring const name = classname_w(begin, end);
- if(name == L"alnum") return _ALPHA|_DIGIT;
- if(name == L"alpha") return _ALPHA;
- if(name == L"blank") return _BLANK; // this is ONLY space!!!
- if(name == L"cntrl") return _CONTROL;
- if(name == L"d") return _DIGIT;
- if(name == L"digit") return _DIGIT;
- if(name == L"graph") return _PUNCT|_ALPHA|_DIGIT;
- if(name == L"lower") return icase ? (_LOWER|_UPPER) : _LOWER;
- if(name == L"newline") return char_class_newline;
- if(name == L"print") return _BLANK|_PUNCT|_ALPHA|_DIGIT;
- if(name == L"punct") return _PUNCT;
- if(name == L"s") return _SPACE;
- if(name == L"space") return _SPACE;
- if(name == L"upper") return icase ? (_UPPER|_LOWER) : _UPPER;
- if(name == L"w") return _ALPHA|_DIGIT|char_class_underscore;
- if(name == L"xdigit") return _HEX;
- return 0;
- }
- static bool isctype(wchar_t ch, char_class_type mask)
- {
- using namespace std;
- if(0 != iswctype(ch, mask))
- {
- return true;
- }
- switch(ch)
- {
- case L'\t': return 0 != (mask & _BLANK);
- case L'_': return 0 != (mask & char_class_underscore);
- case L'\n': case L'\r': case L'\f': case 0x2028u: case 0x2029u: case 0x85u:
- return 0 != (mask & char_class_newline);
- default:;
- }
- return false;
- }
- };
- #endif
- #elif defined(__CYGWIN__)
- ///////////////////////////////////////////////////////////////////////////////
- //
- template<>
- struct char_class_impl<char>
- {
- typedef int char_class_type;
- BOOST_MPL_ASSERT_RELATION(0377, ==, (_U|_L|_N|_S|_P|_C|_B|_X));
- BOOST_STATIC_CONSTANT(int, char_class_underscore = 0400);
- BOOST_STATIC_CONSTANT(int, char_class_newline = 01000);
- template<typename FwdIter>
- static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
- {
- using namespace std;
- string const name = classname_a(begin, end);
- if(name == "alnum") return _U|_L|_N;
- if(name == "alpha") return _U|_L;
- if(name == "blank") return _B; // BUGBUG what is this?
- if(name == "cntrl") return _C;
- if(name == "d") return _N;
- if(name == "digit") return _N;
- if(name == "graph") return _P|_U|_L|_N;
- if(name == "lower") return icase ? (_L|_U) : _L;
- if(name == "newline") return char_class_newline;
- if(name == "print") return _B|_P|_U|_L|_N;
- if(name == "punct") return _P;
- if(name == "s") return _S;
- if(name == "space") return _S;
- if(name == "upper") return icase ? (_U|_L) : _U;
- if(name == "w") return _U|_L|_N|char_class_underscore;
- if(name == "xdigit") return _X;
- return 0;
- }
- static bool isctype(char ch, char_class_type mask)
- {
- if(0 != static_cast<unsigned char>(((_ctype_+1)[(unsigned)(ch)]) & mask))
- {
- return true;
- }
- switch(ch)
- {
- case '_': return 0 != (mask & char_class_underscore);
- case '\n': case '\r': case '\f': return 0 != (mask & char_class_newline);
- default:;
- }
- return false;
- }
- };
- #ifndef BOOST_XPRESSIVE_NO_WREGEX
- ///////////////////////////////////////////////////////////////////////////////
- //
- template<>
- struct char_class_impl<wchar_t>
- {
- typedef int char_class_type;
- //BOOST_STATIC_CONSTANT(int, char_class_alnum = 0x0001);
- BOOST_STATIC_CONSTANT(int, char_class_alpha = 0x0002);
- BOOST_STATIC_CONSTANT(int, char_class_blank = 0x0004);
- BOOST_STATIC_CONSTANT(int, char_class_cntrl = 0x0008);
- BOOST_STATIC_CONSTANT(int, char_class_digit = 0x0010);
- //BOOST_STATIC_CONSTANT(int, char_class_graph = 0x0020);
- BOOST_STATIC_CONSTANT(int, char_class_lower = 0x0040);
- //BOOST_STATIC_CONSTANT(int, char_class_print = 0x0080);
- BOOST_STATIC_CONSTANT(int, char_class_punct = 0x0100);
- BOOST_STATIC_CONSTANT(int, char_class_space = 0x0200);
- BOOST_STATIC_CONSTANT(int, char_class_upper = 0x0400);
- BOOST_STATIC_CONSTANT(int, char_class_underscore = 0x0800);
- BOOST_STATIC_CONSTANT(int, char_class_xdigit = 0x1000);
- BOOST_STATIC_CONSTANT(int, char_class_newline = 0x2000);
- template<typename FwdIter>
- static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
- {
- using namespace std;
- wstring const name = classname_w(begin, end);
- if(name == L"alnum") return char_class_alpha|char_class_digit;
- if(name == L"alpha") return char_class_alpha;
- if(name == L"blank") return char_class_blank;
- if(name == L"cntrl") return char_class_cntrl;
- if(name == L"d") return char_class_digit;
- if(name == L"digit") return char_class_digit;
- if(name == L"graph") return char_class_punct|char_class_alpha|char_class_digit;
- if(name == L"lower") return icase ? (char_class_lower|char_class_upper) : char_class_lower;
- if(name == L"newline") return char_class_newline;
- if(name == L"print") return char_class_blank|char_class_punct|char_class_alpha|char_class_digit;
- if(name == L"punct") return char_class_punct;
- if(name == L"s") return char_class_space;
- if(name == L"space") return char_class_space;
- if(name == L"upper") return icase ? (char_class_upper|char_class_lower) : char_class_upper;
- if(name == L"w") return char_class_alpha|char_class_digit|char_class_underscore;
- if(name == L"xdigit") return char_class_xdigit;
- return 0;
- }
- static bool isctype(wchar_t ch, char_class_type mask)
- {
- using namespace std;
- return ((char_class_alpha & mask) && iswalpha(ch))
- || ((char_class_blank & mask) && (L' ' == ch || L'\t' == ch)) // BUGBUG
- || ((char_class_cntrl & mask) && iswcntrl(ch))
- || ((char_class_digit & mask) && iswdigit(ch))
- || ((char_class_lower & mask) && iswlower(ch))
- || ((char_class_newline & mask) && detail::iswnewline(ch))
- || ((char_class_punct & mask) && iswpunct(ch))
- || ((char_class_space & mask) && iswspace(ch))
- || ((char_class_upper & mask) && iswupper(ch))
- || ((char_class_underscore & mask) && L'_' == ch)
- || ((char_class_xdigit & mask) && iswxdigit(ch))
- ;
- }
- };
- #endif
- #elif defined(__GLIBC__)
- ///////////////////////////////////////////////////////////////////////////////
- //
- template<>
- struct char_class_impl<char>
- {
- typedef int char_class_type;
- BOOST_MPL_ASSERT_RELATION(0xffff, ==, (_ISalnum|_ISalpha|_ISblank|_IScntrl|_ISdigit|_ISgraph|
- _ISlower|_ISprint|_ISpunct|_ISspace|_ISupper|_ISxdigit|0xffff));
- BOOST_STATIC_CONSTANT(int, char_class_underscore = 0x00010000);
- BOOST_STATIC_CONSTANT(int, char_class_newline = 0x00020000);
- template<typename FwdIter>
- static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
- {
- using namespace std;
- string const name = classname_a(begin, end);
- if(name == "alnum") return _ISalnum;
- if(name == "alpha") return _ISalpha;
- if(name == "blank") return _ISblank;
- if(name == "cntrl") return _IScntrl;
- if(name == "d") return _ISdigit;
- if(name == "digit") return _ISdigit;
- if(name == "graph") return _ISgraph;
- if(name == "lower") return icase ? (_ISlower|_ISupper) : _ISlower;
- if(name == "print") return _ISprint;
- if(name == "newline") return char_class_newline;
- if(name == "punct") return _ISpunct;
- if(name == "s") return _ISspace;
- if(name == "space") return _ISspace;
- if(name == "upper") return icase ? (_ISupper|_ISlower) : _ISupper;
- if(name == "w") return _ISalnum|char_class_underscore;
- if(name == "xdigit") return _ISxdigit;
- return 0;
- }
- static bool isctype(char ch, char_class_type mask)
- {
- if(glibc_isctype(ch, mask))
- {
- return true;
- }
- switch(ch)
- {
- case '_': return 0 != (mask & char_class_underscore);
- case '\n': case '\r': case '\f': return 0 != (mask & char_class_newline);
- default:;
- }
- return false;
- }
- static bool glibc_isctype(char ch, char_class_type mask)
- {
- #ifdef __isctype
- return 0 != __isctype(ch, mask);
- #else
- return 0 != ((*__ctype_b_loc())[(int)(ch)] & (unsigned short int)mask);
- #endif
- }
- };
- #ifndef BOOST_XPRESSIVE_NO_WREGEX
- ///////////////////////////////////////////////////////////////////////////////
- //
- template<>
- struct char_class_impl<wchar_t>
- {
- typedef int char_class_type;
- //BOOST_STATIC_CONSTANT(int, char_class_alnum = 0x0001);
- BOOST_STATIC_CONSTANT(int, char_class_alpha = 0x0002);
- BOOST_STATIC_CONSTANT(int, char_class_blank = 0x0004);
- BOOST_STATIC_CONSTANT(int, char_class_cntrl = 0x0008);
- BOOST_STATIC_CONSTANT(int, char_class_digit = 0x0010);
- //BOOST_STATIC_CONSTANT(int, char_class_graph = 0x0020);
- BOOST_STATIC_CONSTANT(int, char_class_lower = 0x0040);
- //BOOST_STATIC_CONSTANT(int, char_class_print = 0x0080);
- BOOST_STATIC_CONSTANT(int, char_class_punct = 0x0100);
- BOOST_STATIC_CONSTANT(int, char_class_space = 0x0200);
- BOOST_STATIC_CONSTANT(int, char_class_upper = 0x0400);
- BOOST_STATIC_CONSTANT(int, char_class_underscore = 0x0800);
- BOOST_STATIC_CONSTANT(int, char_class_xdigit = 0x1000);
- BOOST_STATIC_CONSTANT(int, char_class_newline = 0x2000);
- template<typename FwdIter>
- static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
- {
- using namespace std;
- wstring const name = classname_w(begin, end);
- if(name == L"alnum") return char_class_alpha|char_class_digit;
- if(name == L"alpha") return char_class_alpha;
- if(name == L"blank") return char_class_blank;
- if(name == L"cntrl") return char_class_cntrl;
- if(name == L"d") return char_class_digit;
- if(name == L"digit") return char_class_digit;
- if(name == L"graph") return char_class_punct|char_class_alpha|char_class_digit;
- if(name == L"lower") return icase ? (char_class_lower|char_class_upper) : char_class_lower;
- if(name == L"newline") return char_class_newline;
- if(name == L"print") return char_class_blank|char_class_punct|char_class_alpha|char_class_digit;
- if(name == L"punct") return char_class_punct;
- if(name == L"s") return char_class_space;
- if(name == L"space") return char_class_space;
- if(name == L"upper") return icase ? (char_class_upper|char_class_lower) : char_class_upper;
- if(name == L"w") return char_class_alpha|char_class_digit|char_class_underscore;
- if(name == L"xdigit") return char_class_xdigit;
- return 0;
- }
- static bool isctype(wchar_t ch, char_class_type mask)
- {
- using namespace std;
- return ((char_class_alpha & mask) && iswalpha(ch))
- || ((char_class_blank & mask) && (L' ' == ch || L'\t' == ch)) // BUGBUG
- || ((char_class_cntrl & mask) && iswcntrl(ch))
- || ((char_class_digit & mask) && iswdigit(ch))
- || ((char_class_lower & mask) && iswlower(ch))
- || ((char_class_newline & mask) && detail::iswnewline(ch))
- || ((char_class_punct & mask) && iswpunct(ch))
- || ((char_class_space & mask) && iswspace(ch))
- || ((char_class_upper & mask) && iswupper(ch))
- || ((char_class_underscore & mask) && L'_' == ch)
- || ((char_class_xdigit & mask) && iswxdigit(ch))
- ;
- }
- };
- #endif
- #elif defined(_CPPLIB_VER) // Dinkumware STL
- ///////////////////////////////////////////////////////////////////////////////
- //
- template<>
- struct char_class_impl<char>
- {
- typedef int char_class_type;
- BOOST_MPL_ASSERT_RELATION(0x81FF, ==, (_ALPHA|_UPPER|_LOWER|_DIGIT|_SPACE|_PUNCT|_CONTROL|_BLANK|_HEX|_LEADBYTE));
- BOOST_STATIC_CONSTANT(int, char_class_underscore = 0x1000);
- BOOST_STATIC_CONSTANT(int, char_class_newline = 0x2000);
- template<typename FwdIter>
- static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
- {
- using namespace std;
- string const name = classname_a(begin, end);
- if(name == "alnum") return _ALPHA|_DIGIT;
- if(name == "alpha") return _ALPHA;
- if(name == "blank") return _BLANK; // this is ONLY space!!!
- if(name == "cntrl") return _CONTROL;
- if(name == "d") return _DIGIT;
- if(name == "digit") return _DIGIT;
- if(name == "graph") return _PUNCT|_ALPHA|_DIGIT;
- if(name == "lower") return icase ? (_LOWER|_UPPER) : _LOWER;
- if(name == "newline") return char_class_newline;
- if(name == "print") return _BLANK|_PUNCT|_ALPHA|_DIGIT;
- if(name == "punct") return _PUNCT;
- if(name == "s") return _SPACE;
- if(name == "space") return _SPACE;
- if(name == "upper") return icase ? (_UPPER|_LOWER) : _UPPER;
- if(name == "w") return _ALPHA|_DIGIT|char_class_underscore;
- if(name == "xdigit") return _HEX;
- return 0;
- }
- static bool isctype(char ch, char_class_type mask)
- {
- using namespace std;
- if(0 != _isctype(static_cast<unsigned char>(ch), mask))
- {
- return true;
- }
- switch(ch)
- {
- case '\t': return 0 != (mask & _BLANK);
- case '_': return 0 != (mask & char_class_underscore);
- case '\n': case '\r': case '\f': return 0 != (mask & char_class_newline);
- default:;
- }
- return false;
- }
- };
- #ifndef BOOST_XPRESSIVE_NO_WREGEX
- ///////////////////////////////////////////////////////////////////////////////
- //
- template<>
- struct char_class_impl<wchar_t>
- {
- typedef wctype_t char_class_type;
- BOOST_MPL_ASSERT_RELATION(0x81FF, ==, (_ALPHA|_UPPER|_LOWER|_DIGIT|_SPACE|_PUNCT|_CONTROL|_BLANK|_HEX|_LEADBYTE));
- BOOST_STATIC_CONSTANT(int, char_class_underscore = 0x1000);
- BOOST_STATIC_CONSTANT(int, char_class_newline = 0x2000);
- template<typename FwdIter>
- static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
- {
- using namespace std;
- wstring const name = classname_w(begin, end);
- if(name == L"alnum") return _ALPHA|_DIGIT;
- if(name == L"alpha") return _ALPHA;
- if(name == L"blank") return _BLANK; // this is ONLY space!!!
- if(name == L"cntrl") return _CONTROL;
- if(name == L"d") return _DIGIT;
- if(name == L"digit") return _DIGIT;
- if(name == L"graph") return _PUNCT|_ALPHA|_DIGIT;
- if(name == L"lower") return icase ? _LOWER|_UPPER : _LOWER;
- if(name == L"newline") return char_class_newline;
- if(name == L"print") return _BLANK|_PUNCT|_ALPHA|_DIGIT;
- if(name == L"punct") return _PUNCT;
- if(name == L"s") return _SPACE;
- if(name == L"space") return _SPACE;
- if(name == L"upper") return icase ? _UPPER|_LOWER : _UPPER;
- if(name == L"w") return _ALPHA|_DIGIT|char_class_underscore;
- if(name == L"xdigit") return _HEX;
- return 0;
- }
- static bool isctype(wchar_t ch, char_class_type mask)
- {
- using namespace std;
- if(0 != iswctype(ch, mask))
- {
- return true;
- }
- switch(ch)
- {
- case L'\t': return 0 != (mask & _BLANK);
- case L'_': return 0 != (mask & char_class_underscore);
- case L'\n': case L'\r': case L'\f': case 0x2028u: case 0x2029u: case 0x85u:
- return 0 != (mask & char_class_newline);
- default:;
- }
- return false;
- }
- };
- #endif
- #else // unknown, use portable implementation
- ///////////////////////////////////////////////////////////////////////////////
- //
- template<>
- struct char_class_impl<char>
- {
- typedef int char_class_type;
- //BOOST_STATIC_CONSTANT(int, char_class_alnum = 0x0001);
- BOOST_STATIC_CONSTANT(int, char_class_alpha = 0x0002);
- BOOST_STATIC_CONSTANT(int, char_class_blank = 0x0004);
- BOOST_STATIC_CONSTANT(int, char_class_cntrl = 0x0008);
- BOOST_STATIC_CONSTANT(int, char_class_digit = 0x0010);
- //BOOST_STATIC_CONSTANT(int, char_class_graph = 0x0020);
- BOOST_STATIC_CONSTANT(int, char_class_lower = 0x0040);
- //BOOST_STATIC_CONSTANT(int, char_class_print = 0x0080);
- BOOST_STATIC_CONSTANT(int, char_class_punct = 0x0100);
- BOOST_STATIC_CONSTANT(int, char_class_space = 0x0200);
- BOOST_STATIC_CONSTANT(int, char_class_upper = 0x0400);
- BOOST_STATIC_CONSTANT(int, char_class_underscore = 0x0800);
- BOOST_STATIC_CONSTANT(int, char_class_xdigit = 0x1000);
- BOOST_STATIC_CONSTANT(int, char_class_newline = 0x2000);
- template<typename FwdIter>
- static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
- {
- using namespace std;
- string const name = classname_a(begin, end);
- if(name == "alnum") return char_class_alpha|char_class_digit;
- if(name == "alpha") return char_class_alpha;
- if(name == "blank") return char_class_blank;
- if(name == "cntrl") return char_class_cntrl;
- if(name == "d") return char_class_digit;
- if(name == "digit") return char_class_digit;
- if(name == "graph") return char_class_punct|char_class_alpha|char_class_digit;
- if(name == "lower") return icase ? (char_class_lower|char_class_upper) : char_class_lower;
- if(name == "newline") return char_class_newline;
- if(name == "print") return char_class_blank|char_class_punct|char_class_alpha|char_class_digit;
- if(name == "punct") return char_class_punct;
- if(name == "s") return char_class_space;
- if(name == "space") return char_class_space;
- if(name == "upper") return icase ? (char_class_upper|char_class_lower) : char_class_upper;
- if(name == "w") return char_class_alpha|char_class_digit|char_class_underscore;
- if(name == "xdigit") return char_class_xdigit;
- return 0;
- }
- static bool isctype(char ch, char_class_type mask)
- {
- using namespace std;
- unsigned char uch = static_cast<unsigned char>(ch);
- return ((char_class_alpha & mask) && isalpha(uch))
- || ((char_class_blank & mask) && (' ' == ch || '\t' == ch)) // BUGBUG
- || ((char_class_cntrl & mask) && iscntrl(uch))
- || ((char_class_digit & mask) && isdigit(uch))
- || ((char_class_lower & mask) && islower(uch))
- || ((char_class_newline & mask) && detail::isnewline(ch))
- || ((char_class_punct & mask) && ispunct(uch))
- || ((char_class_space & mask) && isspace(uch))
- || ((char_class_upper & mask) && isupper(uch))
- || ((char_class_underscore & mask) && '_' == ch)
- || ((char_class_xdigit & mask) && isxdigit(uch))
- ;
- }
- };
- #ifndef BOOST_XPRESSIVE_NO_WREGEX
- ///////////////////////////////////////////////////////////////////////////////
- //
- template<>
- struct char_class_impl<wchar_t>
- {
- typedef int char_class_type;
- //BOOST_STATIC_CONSTANT(int, char_class_alnum = 0x0001);
- BOOST_STATIC_CONSTANT(int, char_class_alpha = 0x0002);
- BOOST_STATIC_CONSTANT(int, char_class_blank = 0x0004);
- BOOST_STATIC_CONSTANT(int, char_class_cntrl = 0x0008);
- BOOST_STATIC_CONSTANT(int, char_class_digit = 0x0010);
- //BOOST_STATIC_CONSTANT(int, char_class_graph = 0x0020);
- BOOST_STATIC_CONSTANT(int, char_class_lower = 0x0040);
- //BOOST_STATIC_CONSTANT(int, char_class_print = 0x0080);
- BOOST_STATIC_CONSTANT(int, char_class_punct = 0x0100);
- BOOST_STATIC_CONSTANT(int, char_class_space = 0x0200);
- BOOST_STATIC_CONSTANT(int, char_class_upper = 0x0400);
- BOOST_STATIC_CONSTANT(int, char_class_underscore = 0x0800);
- BOOST_STATIC_CONSTANT(int, char_class_xdigit = 0x1000);
- BOOST_STATIC_CONSTANT(int, char_class_newline = 0x2000);
- template<typename FwdIter>
- static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
- {
- using namespace std;
- wstring const name = classname_w(begin, end);
- if(name == L"alnum") return char_class_alpha|char_class_digit;
- if(name == L"alpha") return char_class_alpha;
- if(name == L"blank") return char_class_blank;
- if(name == L"cntrl") return char_class_cntrl;
- if(name == L"d") return char_class_digit;
- if(name == L"digit") return char_class_digit;
- if(name == L"graph") return char_class_punct|char_class_alpha|char_class_digit;
- if(name == L"newline") return char_class_newline;
- if(name == L"lower") return icase ? (char_class_lower|char_class_upper) : char_class_lower;
- if(name == L"print") return char_class_blank|char_class_punct|char_class_alpha|char_class_digit;
- if(name == L"punct") return char_class_punct;
- if(name == L"s") return char_class_space;
- if(name == L"space") return char_class_space;
- if(name == L"upper") return icase ? (char_class_upper|char_class_lower) : char_class_upper;
- if(name == L"w") return char_class_alpha|char_class_digit|char_class_underscore;
- if(name == L"xdigit") return char_class_xdigit;
- return 0;
- }
- static bool isctype(wchar_t ch, char_class_type mask)
- {
- using namespace std;
- return ((char_class_alpha & mask) && iswalpha(ch))
- || ((char_class_blank & mask) && (L' ' == ch || L'\t' == ch)) // BUGBUG
- || ((char_class_cntrl & mask) && iswcntrl(ch))
- || ((char_class_digit & mask) && iswdigit(ch))
- || ((char_class_lower & mask) && iswlower(ch))
- || ((char_class_newline & mask) && detail::iswnewline(ch))
- || ((char_class_punct & mask) && iswpunct(ch))
- || ((char_class_space & mask) && iswspace(ch))
- || ((char_class_upper & mask) && iswupper(ch))
- || ((char_class_underscore & mask) && L'_' == ch)
- || ((char_class_xdigit & mask) && iswxdigit(ch))
- ;
- }
- };
- #endif
- #endif
- }}} // namespace boost::xpressive::detail
- #endif
|