Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:44:55

0001 //
0002 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0.
0005 // https://www.boost.org/LICENSE_1_0.txt
0006 
0007 #ifndef BOOST_LOCALE_BOUNDARY_BOUNDARY_POINT_HPP_INCLUDED
0008 #define BOOST_LOCALE_BOUNDARY_BOUNDARY_POINT_HPP_INCLUDED
0009 
0010 #include <boost/locale/boundary/types.hpp>
0011 #include <string>
0012 
0013 namespace boost { namespace locale { namespace boundary {
0014 
0015     /// \addtogroup boundary
0016     /// @{
0017 
0018     /// \brief This class represents a boundary point in the text.
0019     ///
0020     /// It represents a pair - an iterator and a rule that defines this
0021     /// point.
0022     ///
0023     /// This type of object is dereferenced by the iterators of boundary_point_index. Using a rule()
0024     /// member function you can get the reason why this specific boundary point was selected.
0025     ///
0026     /// For example, when you use sentence boundary analysis, the (rule() & \ref sentence_term) != 0 means
0027     /// that this boundary point was selected because a sentence terminator (like .?!) was spotted
0028     /// and the (rule() & \ref sentence_sep)!=0 means that a separator like line feed or carriage
0029     /// return was observed.
0030     ///
0031     /// \note
0032     ///
0033     /// -   The beginning of the analyzed range is always considered a boundary point and its rule is always 0.
0034     /// -   When using word boundary analysis, the returned rule relates to a chunk of text preceding
0035     ///     this point.
0036     ///
0037     /// \see
0038     ///
0039     /// -   \ref boundary_point_index
0040     /// -   \ref segment
0041     /// -   \ref segment_index
0042     ///
0043     template<typename IteratorType>
0044     class boundary_point {
0045     public:
0046         /// The type of the base iterator that iterates the original text
0047         typedef IteratorType iterator_type;
0048 
0049         /// Empty default constructor
0050         boundary_point() : rule_(0) {}
0051 
0052         /// Create a new boundary_point using iterator \p and a rule \a r
0053         boundary_point(iterator_type p, rule_type r) : iterator_(p), rule_(r) {}
0054 
0055         /// Set an new iterator value \a i
0056         void iterator(iterator_type i) { iterator_ = i; }
0057         /// Fetch an iterator
0058         iterator_type iterator() const { return iterator_; }
0059 
0060         /// Set an new rule value \a r
0061         void rule(rule_type r) { rule_ = r; }
0062         /// Fetch a rule
0063         rule_type rule() const { return rule_; }
0064 
0065         /// Check if two boundary points are the same
0066         bool operator==(const boundary_point& other) const
0067         {
0068             return iterator_ == other.iterator_ && rule_ = other.rule_;
0069         }
0070         /// Check if two boundary points are different
0071         bool operator!=(const boundary_point& other) const { return !(*this == other); }
0072 
0073         /// Check if the boundary point points to same location as an iterator \a other
0074         bool operator==(const iterator_type& other) const { return iterator_ == other; }
0075         /// Check if the boundary point points to different location from an iterator \a other
0076         bool operator!=(const iterator_type& other) const { return iterator_ != other; }
0077 
0078         /// Automatic cast to the iterator it represents
0079         operator iterator_type() const { return iterator_; }
0080 
0081     private:
0082         iterator_type iterator_;
0083         rule_type rule_;
0084     };
0085 
0086     /// Check if the boundary point \a r points to same location as an iterator \a l
0087     template<typename BaseIterator>
0088     bool operator==(const BaseIterator& l, const boundary_point<BaseIterator>& r)
0089     {
0090         return r == l;
0091     }
0092     /// Check if the boundary point \a r points to different location from an iterator \a l
0093     template<typename BaseIterator>
0094     bool operator!=(const BaseIterator& l, const boundary_point<BaseIterator>& r)
0095     {
0096         return r != l;
0097     }
0098 
0099     /// @}
0100 
0101     typedef boundary_point<std::string::const_iterator> sboundary_point;   ///< convenience typedef
0102     typedef boundary_point<std::wstring::const_iterator> wsboundary_point; ///< convenience typedef
0103 #ifndef BOOST_LOCALE_NO_CXX20_STRING8
0104     typedef boundary_point<std::u8string::const_iterator> u8sboundary_point; ///< convenience typedef
0105 #endif
0106 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
0107     typedef boundary_point<std::u16string::const_iterator> u16sboundary_point; ///< convenience typedef
0108 #endif
0109 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
0110     typedef boundary_point<std::u32string::const_iterator> u32sboundary_point; ///< convenience typedef
0111 #endif
0112 
0113     typedef boundary_point<const char*> cboundary_point;     ///< convenience typedef
0114     typedef boundary_point<const wchar_t*> wcboundary_point; ///< convenience typedef
0115 #ifdef __cpp_char8_t
0116     typedef boundary_point<const char8_t*> u8cboundary_point; ///< convenience typedef
0117 #endif
0118 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
0119     typedef boundary_point<const char16_t*> u16cboundary_point; ///< convenience typedef
0120 #endif
0121 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
0122     typedef boundary_point<const char32_t*> u32cboundary_point; ///< convenience typedef
0123 #endif
0124 
0125 }}} // namespace boost::locale::boundary
0126 
0127 #endif