File indexing completed on 2025-01-18 09:51:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_REGEX_V4_U32REGEX_ITERATOR_HPP
0020 #define BOOST_REGEX_V4_U32REGEX_ITERATOR_HPP
0021
0022 namespace boost{
0023
0024 #ifdef BOOST_HAS_ABI_HEADERS
0025 # include BOOST_ABI_PREFIX
0026 #endif
0027
0028 template <class BidirectionalIterator>
0029 class u32regex_iterator_implementation
0030 {
0031 typedef u32regex regex_type;
0032
0033 match_results<BidirectionalIterator> what;
0034 BidirectionalIterator base;
0035 BidirectionalIterator end;
0036 const regex_type re;
0037 match_flag_type flags;
0038
0039 public:
0040 u32regex_iterator_implementation(const regex_type* p, BidirectionalIterator last, match_flag_type f)
0041 : base(), end(last), re(*p), flags(f){}
0042 bool init(BidirectionalIterator first)
0043 {
0044 base = first;
0045 return u32regex_search(first, end, what, re, flags, base);
0046 }
0047 bool compare(const u32regex_iterator_implementation& that)
0048 {
0049 if(this == &that) return true;
0050 return (&re.get_data() == &that.re.get_data()) && (end == that.end) && (flags == that.flags) && (what[0].first == that.what[0].first) && (what[0].second == that.what[0].second);
0051 }
0052 const match_results<BidirectionalIterator>& get()
0053 { return what; }
0054 bool next()
0055 {
0056
0057
0058 BidirectionalIterator next_start = what[0].second;
0059 match_flag_type f(flags);
0060 if(!what.length())
0061 f |= regex_constants::match_not_initial_null;
0062
0063
0064 bool result = u32regex_search(next_start, end, what, re, f, base);
0065 if(result)
0066 what.set_base(base);
0067 return result;
0068 }
0069 private:
0070 u32regex_iterator_implementation& operator=(const u32regex_iterator_implementation&);
0071 };
0072
0073 template <class BidirectionalIterator>
0074 class u32regex_iterator
0075 {
0076 private:
0077 typedef u32regex_iterator_implementation<BidirectionalIterator> impl;
0078 typedef shared_ptr<impl> pimpl;
0079 public:
0080 typedef u32regex regex_type;
0081 typedef match_results<BidirectionalIterator> value_type;
0082 typedef typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits<BidirectionalIterator>::difference_type
0083 difference_type;
0084 typedef const value_type* pointer;
0085 typedef const value_type& reference;
0086 typedef std::forward_iterator_tag iterator_category;
0087
0088 u32regex_iterator(){}
0089 u32regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
0090 const regex_type& re,
0091 match_flag_type m = match_default)
0092 : pdata(new impl(&re, b, m))
0093 {
0094 if(!pdata->init(a))
0095 {
0096 pdata.reset();
0097 }
0098 }
0099 u32regex_iterator(const u32regex_iterator& that)
0100 : pdata(that.pdata) {}
0101 u32regex_iterator& operator=(const u32regex_iterator& that)
0102 {
0103 pdata = that.pdata;
0104 return *this;
0105 }
0106 bool operator==(const u32regex_iterator& that)const
0107 {
0108 if((pdata.get() == 0) || (that.pdata.get() == 0))
0109 return pdata.get() == that.pdata.get();
0110 return pdata->compare(*(that.pdata.get()));
0111 }
0112 bool operator!=(const u32regex_iterator& that)const
0113 { return !(*this == that); }
0114 const value_type& operator*()const
0115 { return pdata->get(); }
0116 const value_type* operator->()const
0117 { return &(pdata->get()); }
0118 u32regex_iterator& operator++()
0119 {
0120 cow();
0121 if(0 == pdata->next())
0122 {
0123 pdata.reset();
0124 }
0125 return *this;
0126 }
0127 u32regex_iterator operator++(int)
0128 {
0129 u32regex_iterator result(*this);
0130 ++(*this);
0131 return result;
0132 }
0133 private:
0134
0135 pimpl pdata;
0136
0137 void cow()
0138 {
0139
0140 if(pdata.get() && !pdata.unique())
0141 {
0142 pdata.reset(new impl(*(pdata.get())));
0143 }
0144 }
0145 };
0146
0147 typedef u32regex_iterator<const char*> utf8regex_iterator;
0148 typedef u32regex_iterator<const UChar*> utf16regex_iterator;
0149 typedef u32regex_iterator<const UChar32*> utf32regex_iterator;
0150
0151 inline u32regex_iterator<const char*> make_u32regex_iterator(const char* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
0152 {
0153 return u32regex_iterator<const char*>(p, p+std::strlen(p), e, m);
0154 }
0155 #ifndef BOOST_NO_WREGEX
0156 inline u32regex_iterator<const wchar_t*> make_u32regex_iterator(const wchar_t* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
0157 {
0158 return u32regex_iterator<const wchar_t*>(p, p+std::wcslen(p), e, m);
0159 }
0160 #endif
0161 #if !defined(BOOST_REGEX_UCHAR_IS_WCHAR_T)
0162 inline u32regex_iterator<const UChar*> make_u32regex_iterator(const UChar* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
0163 {
0164 return u32regex_iterator<const UChar*>(p, p+u_strlen(p), e, m);
0165 }
0166 #endif
0167 template <class charT, class Traits, class Alloc>
0168 inline u32regex_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
0169 {
0170 typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
0171 return u32regex_iterator<iter_type>(p.begin(), p.end(), e, m);
0172 }
0173 inline u32regex_iterator<const UChar*> make_u32regex_iterator(const U_NAMESPACE_QUALIFIER UnicodeString& s, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
0174 {
0175 return u32regex_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, m);
0176 }
0177
0178 #ifdef BOOST_HAS_ABI_HEADERS
0179 # include BOOST_ABI_SUFFIX
0180 #endif
0181
0182 }
0183
0184 #endif
0185