2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_LOCALE_BOUNDARY_BOUNDARY_POINT_HPP_INCLUDED
9 #define BOOST_LOCALE_BOUNDARY_BOUNDARY_POINT_HPP_INCLUDED
11 #include <boost/locale/boundary/types.hpp>
18 /// \addtogroup boundary
22 /// \brief This class represents a boundary point in the text.
24 /// It represents a pair - an iterator and a rule that defines this
27 /// This type of object is dereference by the iterators of boundary_point_index. Using a rule()
28 /// member function you can get the reason why this specific boundary point was selected.
30 /// For example, When you use a sentence boundary analysis, the (rule() & \ref sentence_term) != 0 means
31 /// that this boundary point was selected because a sentence terminator (like .?!) was spotted
32 /// and the (rule() & \ref sentence_sep)!=0 means that a separator like line feed or carriage
33 /// return was observed.
37 /// - The beginning of analyzed range is always considered a boundary point and its rule is always 0.
38 /// - when using a word boundary analysis the returned rule relates to a chunk of text preceding
43 /// - \ref boundary_point_index
45 /// - \ref segment_index
47 template<typename IteratorType>
48 class boundary_point {
51 /// The type of the base iterator that iterates the original text
53 typedef IteratorType iterator_type;
56 /// Empty default constructor
58 boundary_point() : rule_(0) {}
61 /// Create a new boundary_point using iterator \p and a rule \a r
63 boundary_point(iterator_type p,rule_type r) :
69 /// Set an new iterator value \a i
71 void iterator(iterator_type i)
76 /// Set an new rule value \a r
78 void rule(rule_type r)
85 iterator_type iterator() const
92 rule_type rule() const
97 /// Check if two boundary points are the same
99 bool operator==(boundary_point const &other) const
101 return iterator_ == other.iterator_ && rule_ = other.rule_;
104 /// Check if two boundary points are different
106 bool operator!=(boundary_point const &other) const
108 return !(*this==other);
111 /// Check if the boundary point points to same location as an iterator \a other
113 bool operator==(iterator_type const &other) const
115 return iterator_ == other;
118 /// Check if the boundary point points to different location from an iterator \a other
120 bool operator!=(iterator_type const &other) const
122 return iterator_ != other;
126 /// Automatic cast to the iterator it represents
128 operator iterator_type ()const
134 iterator_type iterator_;
139 /// Check if the boundary point \a r points to same location as an iterator \a l
141 template<typename BaseIterator>
142 bool operator==(BaseIterator const &l,boundary_point<BaseIterator> const &r)
147 /// Check if the boundary point \a r points to different location from an iterator \a l
149 template<typename BaseIterator>
150 bool operator!=(BaseIterator const &l,boundary_point<BaseIterator> const &r)
157 typedef boundary_point<std::string::const_iterator> sboundary_point; ///< convenience typedef
158 typedef boundary_point<std::wstring::const_iterator> wsboundary_point; ///< convenience typedef
159 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
160 typedef boundary_point<std::u16string::const_iterator> u16sboundary_point;///< convenience typedef
162 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
163 typedef boundary_point<std::u32string::const_iterator> u32sboundary_point;///< convenience typedef
166 typedef boundary_point<char const *> cboundary_point; ///< convenience typedef
167 typedef boundary_point<wchar_t const *> wcboundary_point; ///< convenience typedef
168 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
169 typedef boundary_point<char16_t const *> u16cboundary_point; ///< convenience typedef
171 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
172 typedef boundary_point<char32_t const *> u32cboundary_point; ///< convenience typedef
183 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4