Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:51

0001 /*=============================================================================
0002     Copyright (c) 2001-2003 Joel de Guzman
0003     Copyright (c) 2001-2003 Daniel Nuffer
0004     http://spirit.sourceforge.net/
0005 
0006     Use, modification and distribution is subject to the Boost Software
0007     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0008     http://www.boost.org/LICENSE_1_0.txt)
0009 =============================================================================*/
0010 #ifndef BOOST_XPRESSIVE_SPIRIT_BASIC_CHSET_IPP
0011 #define BOOST_XPRESSIVE_SPIRIT_BASIC_CHSET_IPP
0012 
0013 ///////////////////////////////////////////////////////////////////////////////
0014 #include <bitset>
0015 #include <boost/xpressive/detail/utility/chset/basic_chset.hpp>
0016 
0017 ///////////////////////////////////////////////////////////////////////////////
0018 namespace boost { namespace xpressive { namespace detail
0019 {
0020 
0021 ///////////////////////////////////////////////////////////////////////////////
0022 //
0023 //  basic_chset: character set implementation
0024 //
0025 ///////////////////////////////////////////////////////////////////////////////
0026 template<typename Char>
0027 inline basic_chset<Char>::basic_chset()
0028 {
0029 }
0030 
0031 //////////////////////////////////
0032 template<typename Char>
0033 inline basic_chset<Char>::basic_chset(basic_chset const &arg)
0034   : rr_(arg.rr_)
0035 {
0036 }
0037 
0038 //////////////////////////////////
0039 template<typename Char>
0040 inline bool basic_chset<Char>::empty() const
0041 {
0042     return this->rr_.empty();
0043 }
0044 
0045 //////////////////////////////////
0046 template<typename Char>
0047 template<typename Traits>
0048 inline bool basic_chset<Char>::test(Char v, Traits const &, mpl::false_) const // case-sensitive
0049 {
0050     return this->rr_.test(v);
0051 }
0052 
0053 //////////////////////////////////
0054 template<typename Char>
0055 template<typename Traits>
0056 inline bool basic_chset<Char>::test(Char v, Traits const &tr, mpl::true_) const // case-insensitive
0057 {
0058     return this->rr_.test(v, tr);
0059 }
0060 
0061 //////////////////////////////////
0062 template<typename Char>
0063 inline void basic_chset<Char>::set(Char from, Char to)
0064 {
0065     this->rr_.set(range<Char>(from, to));
0066 }
0067 
0068 //////////////////////////////////
0069 template<typename Char>
0070 template<typename Traits>
0071 inline void basic_chset<Char>::set(Char from, Char to, Traits const &)
0072 {
0073     this->rr_.set(range<Char>(from, to));
0074 }
0075 
0076 //////////////////////////////////
0077 template<typename Char>
0078 inline void basic_chset<Char>::set(Char c)
0079 {
0080     this->rr_.set(range<Char>(c, c));
0081 }
0082 
0083 //////////////////////////////////
0084 template<typename Char>
0085 template<typename Traits>
0086 inline void basic_chset<Char>::set(Char c, Traits const &)
0087 {
0088     this->rr_.set(range<Char>(c, c));
0089 }
0090 
0091 //////////////////////////////////
0092 template<typename Char>
0093 inline void basic_chset<Char>::clear(Char c)
0094 {
0095     this->rr_.clear(range<Char>(c, c));
0096 }
0097 
0098 //////////////////////////////////
0099 template<typename Char>
0100 template<typename Traits>
0101 inline void basic_chset<Char>::clear(Char c, Traits const &)
0102 {
0103     this->rr_.clear(range<Char>(c, c));
0104 }
0105 
0106 //////////////////////////////////
0107 template<typename Char>
0108 inline void basic_chset<Char>::clear(Char from, Char to)
0109 {
0110     this->rr_.clear(range<Char>(from, to));
0111 }
0112 
0113 //////////////////////////////////
0114 template<typename Char>
0115 template<typename Traits>
0116 inline void basic_chset<Char>::clear(Char from, Char to, Traits const &)
0117 {
0118     this->rr_.clear(range<Char>(from, to));
0119 }
0120 
0121 //////////////////////////////////
0122 template<typename Char>
0123 inline void basic_chset<Char>::clear()
0124 {
0125     this->rr_.clear();
0126 }
0127 
0128 /////////////////////////////////
0129 template<typename Char>
0130 inline void basic_chset<Char>::inverse()
0131 {
0132     // BUGBUG is this right? Does this handle icase correctly?
0133     basic_chset<Char> inv;
0134     inv.set((std::numeric_limits<Char>::min)(), (std::numeric_limits<Char>::max)());
0135     inv -= *this;
0136     this->swap(inv);
0137 }
0138 
0139 /////////////////////////////////
0140 template<typename Char>
0141 inline void basic_chset<Char>::swap(basic_chset<Char> &that)
0142 {
0143     this->rr_.swap(that.rr_);
0144 }
0145 
0146 /////////////////////////////////
0147 template<typename Char>
0148 inline basic_chset<Char> &
0149 basic_chset<Char>::operator |=(basic_chset<Char> const &that)
0150 {
0151     typedef typename range_run<Char>::const_iterator const_iterator;
0152     for(const_iterator iter = that.rr_.begin(); iter != that.rr_.end(); ++iter)
0153     {
0154         this->rr_.set(*iter);
0155     }
0156     return *this;
0157 }
0158 
0159 /////////////////////////////////
0160 template<typename Char>
0161 inline basic_chset<Char> &
0162 basic_chset<Char>::operator &=(basic_chset<Char> const &that)
0163 {
0164     basic_chset<Char> inv;
0165     inv.set((std::numeric_limits<Char>::min)(), (std::numeric_limits<Char>::max)());
0166     inv -= that;
0167     *this -= inv;
0168     return *this;
0169 }
0170 
0171 /////////////////////////////////
0172 template<typename Char>
0173 inline basic_chset<Char> &
0174 basic_chset<Char>::operator -=(basic_chset<Char> const &that)
0175 {
0176     typedef typename range_run<Char>::const_iterator const_iterator;
0177     for(const_iterator iter = that.rr_.begin(); iter != that.rr_.end(); ++iter)
0178     {
0179         this->rr_.clear(*iter);
0180     }
0181     return *this;
0182 }
0183 
0184 /////////////////////////////////
0185 template<typename Char>
0186 inline basic_chset<Char> &
0187 basic_chset<Char>::operator ^=(basic_chset<Char> const &that)
0188 {
0189     basic_chset bma = that;
0190     bma -= *this;
0191     *this -= that;
0192     *this |= bma;
0193     return *this;
0194 }
0195 
0196 #if(CHAR_BIT == 8)
0197 
0198 ///////////////////////////////////////////////////////////////////////////////
0199 //
0200 //  basic_chset: specializations for 8 bit chars using std::bitset
0201 //
0202 ///////////////////////////////////////////////////////////////////////////////
0203 template<typename Char>
0204 inline basic_chset_8bit<Char>::basic_chset_8bit()
0205 {
0206 }
0207 
0208 /////////////////////////////////
0209 template<typename Char>
0210 inline basic_chset_8bit<Char>::basic_chset_8bit(basic_chset_8bit<Char> const &arg)
0211   : bset_(arg.bset_)
0212 {
0213 }
0214 
0215 /////////////////////////////////
0216 template<typename Char>
0217 inline bool basic_chset_8bit<Char>::empty() const
0218 {
0219     return !this->bset_.any();
0220 }
0221 
0222 /////////////////////////////////
0223 template<typename Char>
0224 template<typename Traits>
0225 inline bool basic_chset_8bit<Char>::test(Char v, Traits const &, mpl::false_) const // case-sensitive
0226 {
0227     return this->bset_.test((unsigned char)v);
0228 }
0229 
0230 /////////////////////////////////
0231 template<typename Char>
0232 template<typename Traits>
0233 inline bool basic_chset_8bit<Char>::test(Char v, Traits const &tr, mpl::true_) const // case-insensitive
0234 {
0235     return this->bset_.test((unsigned char)tr.translate_nocase(v));
0236 }
0237 
0238 /////////////////////////////////
0239 template<typename Char>
0240 inline void basic_chset_8bit<Char>::set(Char from, Char to)
0241 {
0242     for(int i = from; i <= to; ++i)
0243     {
0244         this->bset_.set((unsigned char)i);
0245     }
0246 }
0247 
0248 /////////////////////////////////
0249 template<typename Char>
0250 template<typename Traits>
0251 inline void basic_chset_8bit<Char>::set(Char from, Char to, Traits const &tr)
0252 {
0253     for(int i = from; i <= to; ++i)
0254     {
0255         this->bset_.set((unsigned char)tr.translate_nocase((Char)i));
0256     }
0257 }
0258 
0259 /////////////////////////////////
0260 template<typename Char>
0261 inline void basic_chset_8bit<Char>::set(Char c)
0262 {
0263     this->bset_.set((unsigned char)c);
0264 }
0265 
0266 /////////////////////////////////
0267 template<typename Char>
0268 template<typename Traits>
0269 inline void basic_chset_8bit<Char>::set(Char c, Traits const &tr)
0270 {
0271     this->bset_.set((unsigned char)tr.translate_nocase(c));
0272 }
0273 
0274 /////////////////////////////////
0275 template<typename Char>
0276 inline void basic_chset_8bit<Char>::clear(Char from, Char to)
0277 {
0278     for(int i = from; i <= to; ++i)
0279     {
0280         this->bset_.reset((unsigned char)i);
0281     }
0282 }
0283 
0284 /////////////////////////////////
0285 template<typename Char>
0286 template<typename Traits>
0287 inline void basic_chset_8bit<Char>::clear(Char from, Char to, Traits const &tr)
0288 {
0289     for(int i = from; i <= to; ++i)
0290     {
0291         this->bset_.reset((unsigned char)tr.translate_nocase((Char)i));
0292     }
0293 }
0294 
0295 /////////////////////////////////
0296 template<typename Char>
0297 inline void basic_chset_8bit<Char>::clear(Char c)
0298 {
0299     this->bset_.reset((unsigned char)c);
0300 }
0301 
0302 /////////////////////////////////
0303 template<typename Char>
0304 template<typename Traits>
0305 inline void basic_chset_8bit<Char>::clear(Char c, Traits const &tr)
0306 {
0307     this->bset_.reset((unsigned char)tr.tranlsate_nocase(c));
0308 }
0309 
0310 /////////////////////////////////
0311 template<typename Char>
0312 inline void basic_chset_8bit<Char>::clear()
0313 {
0314     this->bset_.reset();
0315 }
0316 
0317 /////////////////////////////////
0318 template<typename Char>
0319 inline void basic_chset_8bit<Char>::inverse()
0320 {
0321     this->bset_.flip();
0322 }
0323 
0324 /////////////////////////////////
0325 template<typename Char>
0326 inline void basic_chset_8bit<Char>::swap(basic_chset_8bit<Char> &that)
0327 {
0328     std::swap(this->bset_, that.bset_);
0329 }
0330 
0331 /////////////////////////////////
0332 template<typename Char>
0333 inline basic_chset_8bit<Char> &
0334 basic_chset_8bit<Char>::operator |=(basic_chset_8bit<Char> const &that)
0335 {
0336     this->bset_ |= that.bset_;
0337     return *this;
0338 }
0339 
0340 /////////////////////////////////
0341 template<typename Char>
0342 inline basic_chset_8bit<Char> &
0343 basic_chset_8bit<Char>::operator &=(basic_chset_8bit<Char> const &that)
0344 {
0345     this->bset_ &= that.bset_;
0346     return *this;
0347 }
0348 
0349 /////////////////////////////////
0350 template<typename Char>
0351 inline basic_chset_8bit<Char> &
0352 basic_chset_8bit<Char>::operator -=(basic_chset_8bit<Char> const &that)
0353 {
0354     this->bset_ &= ~that.bset_;
0355     return *this;
0356 }
0357 
0358 /////////////////////////////////
0359 template<typename Char>
0360 inline basic_chset_8bit<Char> &
0361 basic_chset_8bit<Char>::operator ^=(basic_chset_8bit<Char> const &that)
0362 {
0363     this->bset_ ^= that.bset_;
0364     return *this;
0365 }
0366 
0367 template<typename Char>
0368 inline std::bitset<256> const &
0369 basic_chset_8bit<Char>::base() const
0370 {
0371     return this->bset_;
0372 }
0373 
0374 #endif // if(CHAR_BIT == 8)
0375 
0376 
0377 ///////////////////////////////////////////////////////////////////////////////
0378 // helpers
0379 template<typename Char, typename Traits>
0380 inline void set_char(basic_chset<Char> &chset, Char ch, Traits const &tr, bool icase)
0381 {
0382     icase ? chset.set(ch, tr) : chset.set(ch);
0383 }
0384 
0385 template<typename Char, typename Traits>
0386 inline void set_range(basic_chset<Char> &chset, Char from, Char to, Traits const &tr, bool icase)
0387 {
0388     icase ? chset.set(from, to, tr) : chset.set(from, to);
0389 }
0390 
0391 template<typename Char, typename Traits>
0392 inline void set_class(basic_chset<Char> &chset, typename Traits::char_class_type char_class, bool no, Traits const &tr)
0393 {
0394     BOOST_MPL_ASSERT_RELATION(1, ==, sizeof(Char));
0395     for(std::size_t i = 0; i <= UCHAR_MAX; ++i)
0396     {
0397         typedef typename std::char_traits<Char>::int_type int_type;
0398         Char ch = std::char_traits<Char>::to_char_type(static_cast<int_type>(i));
0399         if(no != tr.isctype(ch, char_class))
0400         {
0401             chset.set(ch);
0402         }
0403     }
0404 }
0405 
0406 }}} // namespace boost::xpressive::detail
0407 
0408 #endif
0409