~ubuntu-branches/ubuntu/wily/bombono-dvd/wily

« back to all changes in this revision

Viewing changes to libs/boost-lib/boost/regex/v4/cpp_regex_traits.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-04 11:46:25 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101104114625-8xfdhvhpsm51i0nu
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
#include <istream>
43
43
#include <ios>
 
44
#include <climits>
44
45
 
 
46
#ifdef BOOST_MSVC
 
47
#pragma warning(push)
 
48
#pragma warning(disable: 4103)
 
49
#endif
45
50
#ifdef BOOST_HAS_ABI_HEADERS
46
51
#  include BOOST_ABI_PREFIX
47
52
#endif
 
53
#ifdef BOOST_MSVC
 
54
#pragma warning(pop)
 
55
#endif
48
56
 
49
57
#ifdef BOOST_MSVC
50
58
#pragma warning(push)
51
 
#pragma warning(disable:4786)
 
59
#pragma warning(disable:4786 4251)
52
60
#endif
53
61
 
54
62
namespace boost{ 
120
128
      break;
121
129
   case ::std::ios_base::cur:
122
130
   {
123
 
      std::ptrdiff_t newpos = pos + off;
 
131
      std::ptrdiff_t newpos = static_cast<std::ptrdiff_t>(pos + off);
124
132
      if((newpos < 0) || (newpos > size))
125
133
         return pos_type(off_type(-1));
126
134
      else
179
187
#ifndef BOOST_NO_STD_MESSAGES
180
188
         if(m_pmessages == b.m_pmessages)
181
189
         {
 
190
            return m_pcollate < b.m_pcollate;
182
191
         }
183
192
         return m_pmessages < b.m_pmessages;
184
193
#else
204
213
   m_locale = l;
205
214
   m_pctype = &BOOST_USE_FACET(std::ctype<charT>, l);
206
215
#ifndef BOOST_NO_STD_MESSAGES
207
 
   m_pmessages = &BOOST_USE_FACET(std::messages<charT>, l);
 
216
   m_pmessages = BOOST_HAS_FACET(std::messages<charT>, l) ? &BOOST_USE_FACET(std::messages<charT>, l) : 0;
208
217
#endif
209
218
   m_pcollate = &BOOST_USE_FACET(std::collate<charT>, l);
210
219
   return result;
268
277
   typename std::messages<charT>::catalog cat = reinterpret_cast<std::messages<char>::catalog>(-1);
269
278
#endif
270
279
   std::string cat_name(cpp_regex_traits<charT>::get_catalog_name());
271
 
   if(cat_name.size())
 
280
   if(cat_name.size() && (this->m_pmessages != 0))
272
281
   {
273
282
      cat = this->m_pmessages->open(
274
283
         cat_name, 
285
294
   //
286
295
   if((int)cat >= 0)
287
296
   {
 
297
#ifndef BOOST_NO_EXCEPTIONS
288
298
      try{
 
299
#endif
289
300
         for(regex_constants::syntax_type i = 1; i < regex_constants::syntax_max; ++i)
290
301
         {
291
302
            string_type mss = this->m_pmessages->get(cat, 0, i, get_default_message(i));
295
306
            }
296
307
         }
297
308
         this->m_pmessages->close(cat);
 
309
#ifndef BOOST_NO_EXCEPTIONS
298
310
      }
299
311
      catch(...)
300
312
      {
301
 
         this->m_pmessages->close(cat);
 
313
         if(this->m_pmessages)
 
314
            this->m_pmessages->close(cat);
302
315
         throw;
303
316
      }
 
317
#endif
304
318
   }
305
319
   else
306
320
   {
382
396
   char_class_graph=char_class_alnum|char_class_punct,
383
397
   char_class_blank=1<<9,
384
398
   char_class_word=1<<10,
385
 
   char_class_unicode=1<<11
 
399
   char_class_unicode=1<<11,
 
400
   char_class_horizontal_space=1<<12,
 
401
   char_class_vertical_space=1<<13
386
402
};
387
403
 
388
404
#endif
401
417
   BOOST_STATIC_CONSTANT(char_class_type, mask_blank = 1u << 24);
402
418
   BOOST_STATIC_CONSTANT(char_class_type, mask_word = 1u << 25);
403
419
   BOOST_STATIC_CONSTANT(char_class_type, mask_unicode = 1u << 26);
 
420
   BOOST_STATIC_CONSTANT(char_class_type, mask_horizontal = 1u << 27);
 
421
   BOOST_STATIC_CONSTANT(char_class_type, mask_vertical = 1u << 28);
404
422
#endif
405
423
 
406
424
   typedef std::basic_string<charT> string_type;
407
425
   typedef charT char_type;
408
426
   //cpp_regex_traits_implementation();
409
427
   cpp_regex_traits_implementation(const std::locale& l)
410
 
      : cpp_regex_traits_char_layer<charT>(l), m_is(&m_sbuf)
 
428
      : cpp_regex_traits_char_layer<charT>(l)
411
429
   {
412
430
      init();
413
431
   }
414
432
   cpp_regex_traits_implementation(const cpp_regex_traits_base<charT>& l)
415
 
      : cpp_regex_traits_char_layer<charT>(l), m_is(&m_sbuf)
 
433
      : cpp_regex_traits_char_layer<charT>(l)
416
434
   {
417
435
      init();
418
436
   }
439
457
   string_type lookup_collatename(const charT* p1, const charT* p2) const;
440
458
   string_type transform_primary(const charT* p1, const charT* p2) const;
441
459
   string_type transform(const charT* p1, const charT* p2) const;
442
 
   re_detail::parser_buf<charT>   m_sbuf;            // buffer for parsing numbers.
443
 
   std::basic_istream<charT>      m_is;              // stream for parsing numbers.
444
460
private:
445
461
   std::map<int, std::string>     m_error_strings;   // error messages indexed by numberic ID
446
462
   std::map<string_type, char_class_type>  m_custom_class_names; // character class names
467
483
typename cpp_regex_traits_implementation<charT>::char_class_type const cpp_regex_traits_implementation<charT>::mask_word;
468
484
template <class charT>
469
485
typename cpp_regex_traits_implementation<charT>::char_class_type const cpp_regex_traits_implementation<charT>::mask_unicode;
 
486
template <class charT>
 
487
typename cpp_regex_traits_implementation<charT>::char_class_type const cpp_regex_traits_implementation<charT>::mask_vertical;
 
488
template <class charT>
 
489
typename cpp_regex_traits_implementation<charT>::char_class_type const cpp_regex_traits_implementation<charT>::mask_horizontal;
470
490
 
471
491
#endif
472
492
#endif
564
584
      // std::collate<wchar_t>::transform returns a different string!
565
585
      // So as a workaround, we'll truncate the string at the first NULL
566
586
      // which _seems_ to work....
567
 
#if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
 
587
#if BOOST_WORKAROUND(__BORLANDC__, < 0x580)
568
588
      result.erase(result.find(charT(0)));
569
589
#else
570
590
      //
635
655
   typename std::messages<charT>::catalog cat = reinterpret_cast<std::messages<char>::catalog>(-1);
636
656
#endif
637
657
   std::string cat_name(cpp_regex_traits<charT>::get_catalog_name());
638
 
   if(cat_name.size())
 
658
   if(cat_name.size() && (this->m_pmessages != 0))
639
659
   {
640
660
      cat = this->m_pmessages->open(
641
661
         cat_name, 
678
698
      // Custom class names:
679
699
      //
680
700
#ifndef BOOST_REGEX_BUGGY_CTYPE_FACET
681
 
      static const char_class_type masks[14] = 
 
701
      static const char_class_type masks[16] = 
682
702
      {
683
703
         std::ctype<charT>::alnum,
684
704
         std::ctype<charT>::alpha,
685
705
         std::ctype<charT>::cntrl,
686
706
         std::ctype<charT>::digit,
687
707
         std::ctype<charT>::graph,
 
708
         cpp_regex_traits_implementation<charT>::mask_horizontal,
688
709
         std::ctype<charT>::lower,
689
710
         std::ctype<charT>::print,
690
711
         std::ctype<charT>::punct,
691
712
         std::ctype<charT>::space,
692
713
         std::ctype<charT>::upper,
 
714
         cpp_regex_traits_implementation<charT>::mask_vertical,
693
715
         std::ctype<charT>::xdigit,
694
716
         cpp_regex_traits_implementation<charT>::mask_blank,
695
717
         cpp_regex_traits_implementation<charT>::mask_word,
696
718
         cpp_regex_traits_implementation<charT>::mask_unicode,
697
719
      };
698
720
#else
699
 
      static const char_class_type masks[14] = 
 
721
      static const char_class_type masks[16] = 
700
722
      {
701
723
         ::boost::re_detail::char_class_alnum,
702
724
         ::boost::re_detail::char_class_alpha,
703
725
         ::boost::re_detail::char_class_cntrl,
704
726
         ::boost::re_detail::char_class_digit,
705
727
         ::boost::re_detail::char_class_graph,
 
728
         ::boost::re_detail::char_class_horizontal_space,
706
729
         ::boost::re_detail::char_class_lower,
707
730
         ::boost::re_detail::char_class_print,
708
731
         ::boost::re_detail::char_class_punct,
709
732
         ::boost::re_detail::char_class_space,
710
733
         ::boost::re_detail::char_class_upper,
 
734
         ::boost::re_detail::char_class_vertical_space,
711
735
         ::boost::re_detail::char_class_xdigit,
712
736
         ::boost::re_detail::char_class_blank,
713
737
         ::boost::re_detail::char_class_word,
734
758
   cpp_regex_traits_implementation<charT>::lookup_classname_imp(const charT* p1, const charT* p2) const
735
759
{
736
760
#ifndef BOOST_REGEX_BUGGY_CTYPE_FACET
737
 
   static const char_class_type masks[20] = 
 
761
   static const char_class_type masks[22] = 
738
762
   {
739
763
      0,
740
764
      std::ctype<char>::alnum, 
744
768
      std::ctype<char>::digit,
745
769
      std::ctype<char>::digit,
746
770
      std::ctype<char>::graph,
 
771
      cpp_regex_traits_implementation<charT>::mask_horizontal,
747
772
      std::ctype<char>::lower,
748
773
      std::ctype<char>::lower,
749
774
      std::ctype<char>::print,
753
778
      std::ctype<char>::upper,
754
779
      cpp_regex_traits_implementation<charT>::mask_unicode,
755
780
      std::ctype<char>::upper,
 
781
      cpp_regex_traits_implementation<charT>::mask_vertical,
756
782
      std::ctype<char>::alnum | cpp_regex_traits_implementation<charT>::mask_word, 
757
783
      std::ctype<char>::alnum | cpp_regex_traits_implementation<charT>::mask_word, 
758
784
      std::ctype<char>::xdigit,
759
785
   };
760
786
#else
761
 
   static const char_class_type masks[20] = 
 
787
   static const char_class_type masks[22] = 
762
788
   {
763
789
      0,
764
790
      ::boost::re_detail::char_class_alnum, 
768
794
      ::boost::re_detail::char_class_digit,
769
795
      ::boost::re_detail::char_class_digit,
770
796
      ::boost::re_detail::char_class_graph,
 
797
      ::boost::re_detail::char_class_horizontal_space,
771
798
      ::boost::re_detail::char_class_lower,
772
799
      ::boost::re_detail::char_class_lower,
773
800
      ::boost::re_detail::char_class_print,
777
804
      ::boost::re_detail::char_class_upper,
778
805
      ::boost::re_detail::char_class_unicode,
779
806
      ::boost::re_detail::char_class_upper,
 
807
      ::boost::re_detail::char_class_vertical_space,
780
808
      ::boost::re_detail::char_class_alnum | ::boost::re_detail::char_class_word, 
781
809
      ::boost::re_detail::char_class_alnum | ::boost::re_detail::char_class_word, 
782
810
      ::boost::re_detail::char_class_xdigit,
789
817
      if(pos != m_custom_class_names.end())
790
818
         return pos->second;
791
819
   }
792
 
   std::size_t id = 1 + re_detail::get_default_class_id(p1, p2);
793
 
   BOOST_ASSERT(id < sizeof(masks) / sizeof(masks[0]));
794
 
   return masks[id];
 
820
   std::size_t state_id = 1 + re_detail::get_default_class_id(p1, p2);
 
821
   BOOST_ASSERT(state_id < sizeof(masks) / sizeof(masks[0]));
 
822
   return masks[state_id];
795
823
}
796
824
 
797
825
#ifdef BOOST_REGEX_BUGGY_CTYPE_FACET
810
838
      || ((mask & ::boost::re_detail::char_class_xdigit) && (m_pctype->is(std::ctype<charT>::xdigit, c)))
811
839
      || ((mask & ::boost::re_detail::char_class_blank) && (m_pctype->is(std::ctype<charT>::space, c)) && !::boost::re_detail::is_separator(c))
812
840
      || ((mask & ::boost::re_detail::char_class_word) && (c == '_'))
813
 
      || ((mask & ::boost::re_detail::char_class_unicode) && ::boost::re_detail::is_extended(c));
 
841
      || ((mask & ::boost::re_detail::char_class_unicode) && ::boost::re_detail::is_extended(c))
 
842
      || ((mask & ::boost::re_detail::char_class_vertical_space) && (is_separator(c) || (c == '\v')))
 
843
      || ((mask & ::boost::re_detail::char_class_horizontal_space) && m_pctype->is(std::ctype<charT>::space, c) && !(is_separator(c) || (c == '\v')));
814
844
}
815
845
#endif
816
846
 
817
847
 
818
848
template <class charT>
819
 
inline boost::shared_ptr<cpp_regex_traits_implementation<charT> > create_cpp_regex_traits(const std::locale& l BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(charT))
 
849
inline boost::shared_ptr<const cpp_regex_traits_implementation<charT> > create_cpp_regex_traits(const std::locale& l BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(charT))
820
850
{
821
851
   cpp_regex_traits_base<charT> key(l);
822
852
   return ::boost::object_cache<cpp_regex_traits_base<charT>, cpp_regex_traits_implementation<charT> >::get(key, 5);
920
950
         && m_pimpl->m_pctype->is(std::ctype<charT>::space, c)
921
951
         && !re_detail::is_separator(c))
922
952
         return true;
 
953
      else if((f & re_detail::cpp_regex_traits_implementation<charT>::mask_vertical) 
 
954
         && (::boost::re_detail::is_separator(c) || (c == '\v')))
 
955
         return true;
 
956
      else if((f & re_detail::cpp_regex_traits_implementation<charT>::mask_horizontal) 
 
957
         && this->isctype(c, std::ctype<charT>::space) && !this->isctype(c, re_detail::cpp_regex_traits_implementation<charT>::mask_vertical))
 
958
         return true;
923
959
      return false;
924
960
#else
925
961
      return m_pimpl->isctype(c, f);
954
990
   static std::string get_catalog_name();
955
991
 
956
992
private:
957
 
   boost::shared_ptr<re_detail::cpp_regex_traits_implementation<charT> > m_pimpl;
 
993
   boost::shared_ptr<const re_detail::cpp_regex_traits_implementation<charT> > m_pimpl;
958
994
   //
959
995
   // catalog name handler:
960
996
   //
969
1005
template <class charT>
970
1006
int cpp_regex_traits<charT>::toi(const charT*& first, const charT* last, int radix)const
971
1007
{
 
1008
   re_detail::parser_buf<charT>   sbuf;            // buffer for parsing numbers.
 
1009
   std::basic_istream<charT>      is(&sbuf);       // stream for parsing numbers.
 
1010
 
972
1011
   // we do NOT want to parse any thousands separators inside the stream:
973
 
   last = std::find(first, last, BOOST_USE_FACET(std::numpunct<charT>, m_pimpl->m_is.getloc()).thousands_sep());
974
 
   m_pimpl->m_sbuf.pubsetbuf(const_cast<charT*>(static_cast<const charT*>(first)), static_cast<std::streamsize>(last-first));
975
 
   m_pimpl->m_is.clear();
976
 
   if(std::abs(radix) == 16) m_pimpl->m_is >> std::hex;
977
 
   else if(std::abs(radix) == 8) m_pimpl->m_is >> std::oct;
978
 
   else m_pimpl->m_is >> std::dec;
 
1012
   last = std::find(first, last, BOOST_USE_FACET(std::numpunct<charT>, is.getloc()).thousands_sep());
 
1013
 
 
1014
   sbuf.pubsetbuf(const_cast<charT*>(static_cast<const charT*>(first)), static_cast<std::streamsize>(last-first));
 
1015
   is.clear();
 
1016
   if(std::abs(radix) == 16) is >> std::hex;
 
1017
   else if(std::abs(radix) == 8) is >> std::oct;
 
1018
   else is >> std::dec;
979
1019
   int val;
980
 
   if(m_pimpl->m_is >> val)
 
1020
   if(is >> val)
981
1021
   {
982
 
      first = first + ((last - first) - m_pimpl->m_sbuf.in_avail());
 
1022
      first = first + ((last - first) - sbuf.in_avail());
983
1023
      return val;
984
1024
   }
985
1025
   else
1030
1070
#pragma warning(pop)
1031
1071
#endif
1032
1072
 
 
1073
#ifdef BOOST_MSVC
 
1074
#pragma warning(push)
 
1075
#pragma warning(disable: 4103)
 
1076
#endif
1033
1077
#ifdef BOOST_HAS_ABI_HEADERS
1034
1078
#  include BOOST_ABI_SUFFIX
1035
1079
#endif
1036
 
 
1037
 
#endif
1038
 
 
1039
 
#endif
 
1080
#ifdef BOOST_MSVC
 
1081
#pragma warning(pop)
 
1082
#endif
 
1083
 
 
1084
#endif
 
1085
 
 
1086
#endif
 
1087
 
 
1088